How to calculate average for XML attributes which their value equal to zero using the before and after values
-
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.
-
@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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login