Community
    • Login

    How to calculate average for XML attributes which their value equal to zero using the before and after values

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    xmlxml toolsxml schema
    2 Posts 2 Posters 305 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AliMirzaei5778A
      AliMirzaei5778
      last edited by

      Hi,
      I have an XML file in which some values are equal to zero which is not desired. I want to calculate the average and modify the main file with the average values.
      here is my data:

      <timestep time="13.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05"/>
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="2226.31" CO="76.53" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="2101.12" CO="50.74" />
          </timestep>
          <timestep time="14.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05" />
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="0.00" CO="0.00" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="0.00" CO="0.00" />
          </timestep>
          <timestep time="15.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05"/>
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="0.00" CO="0.00" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="0.00" CO="0.00" />
          </timestep>
          <timestep time="16.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05"/>
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="2296.22" CO="80.79" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="2212.41" CO="56.28" />
          </timestep>
      

      The average value must be calculated
      1 - between the vehicles with the same ‘id’.
      2 - only between the before and after timesteps.
      3 - must be modified every timestep.
      The expected result is:

      <timestep time="13.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05"/>
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="2226.31" CO="76.53" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="2101.12" CO="50.74" />
          </timestep>
          <timestep time="14.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05" />
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="1113.16" CO="38.27" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="1050.56" CO="25.37" />
          </timestep>
          <timestep time="15.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05"/>
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="1704.69" CO="59.53" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="1631.49" CO="40.83" />
          </timestep>
          <timestep time="16.00">
              <vehicle id="bus_1" eclass="HBEFA3/Bus" CO2="8165.28" CO="21.05"/>
              <vehicle id="f2.0" eclass="HBEFA3/PC_G_EU4" CO2="2296.22" CO="80.79" />
              <vehicle id="f2.1" eclass="HBEFA3/PC_G_EU4" CO2="2212.41" CO="56.28" />
          </timestep>
      

      For example, in time = ‘14’ for vehicle id = ‘f2.0’, the ‘CO2’ average is ((2226.31 + 0)/2) = 1113.16. We modify the CO2 value for this vehicle at this time and use that for getting the average of the vehicle ‘f2.0’ in the next timestep (time = ‘15’) which would be ((1113.16+2296.22)/2) = 1704.69.

      Any help would be appreciated.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @AliMirzaei5778
        last edited by

        @alimirzaei5778 said in How to calculate average for XML attributes which their value equal to zero using the before and after values:

        Any help would be appreciated.

        Learn a programming language and how to program.

        Seriously, that’s the way.

        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors