RWTH-EBC / pyCity

Python package for data handling and scenario generation of city districts
MIT License
24 stars 3 forks source link

How to calculate time from Timer #220

Closed yuwash closed 6 years ago

yuwash commented 7 years ago

For day, you can just use the currentDay attribute that is set on every update, but for the time one needs to interpret the currentTimestep. When looking at how currentDay is updated at Timer.py#L72:

        newDay = int(self.currentTimestep * 150 / self.timeDiscretization)
        # 150 = 3600 / 24

Though timeDiscretization is described as "A value of 3600 corresponds to one hour.", so it seems to be the length of timesteps measured in seconds, this calculation rather looks like it is the number of timesteps within an hour. I'd appreciate any clarification of it.

It would be probably very useful if it had a method to get elapsed seconds (either total or within the day).

anna-scholl commented 6 years ago

The timer in pyCity only counts the number of hours (if you use timeDescretization = 3600). In https://github.com/RWTH-EBC/CloudEM/blob/master/cloudem/functions/fmu_handling/FMUHandling.py I wrote a function ('timer_to_datetime(timer=None):') to convert the current_timestep to a datetime object (Year is hard coded in this function to 2016). Maybe this helps you?

yuwash commented 6 years ago

Thanks, that's great, I was using timedelta(seconds=timer.currentTimestep*3600/timer.timeDiscretization) not knowing you can set non-integers as days like that.

EDIT: it probably should've been timedelta(seconds=timer.currentTimestep*timer.timeDiscretization)

For the general case then it's then probably:

timedelta(timer.currentTimestep*timer.timeDiscretization/24./3600.)
JSchiefelbein commented 6 years ago

I guess this issue can be closed. Otherwise, please reopen it.