Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series beginDateTime source in ODM2 timeseries DAO? #200

Open
miguelcleon opened this issue Oct 20, 2017 · 13 comments
Open

Series beginDateTime source in ODM2 timeseries DAO? #200

miguelcleon opened this issue Oct 20, 2017 · 13 comments

Comments

@miguelcleon
Copy link
Member

@lsetiawan

I'm looking at the results from the following call, particularly the section below. Where does beginDateTime come from? I tried poking around in the code but I'm not finding it. The listed end date 2016-09-18T13:00:00 is correct but the first record for this time series is on 2016-07-07T10:00. This site was only active for a short time.

http://odm2admin.cuahsi.org/wofpy/odm2lczo/rest/1_1/GetSiteInfo?site=odm2lczo:RESDN


<variable>
<variableCode default="true" vocabulary="odm2lczo" variableID="15">Abs Pres</variableCode>
<variableName>Pressure, absolute</variableName>
<variableDescription>Water Pressure gauge</variableDescription>
<valueType>Observation</valueType>
<dataType>Average</dataType>
<generalCategory>Water quality</generalCategory>
<sampleMedium>Surface water</sampleMedium>
<unit>
<unitName>kilopascal</unitName>
<unitType>Pressure</unitType>
<unitAbbreviation>kPa</unitAbbreviation>
<unitCode>35</unitCode>
</unit>
<noDataValue>-6999.0000000000</noDataValue>
<timeScale/>
</variable>
<valueCount>5</valueCount>
<variableTimeInterval>
<beginDateTime>2014-03-10T09:00:00</beginDateTime>
<endDateTime>2016-09-18T13:00:00</endDateTime>
@lsetiawan
Copy link
Member

It gets it from seriesResult here: https://github.com/ODM2/WOFpy/blob/master/wof/core_1_1.py#L779

@lsetiawan
Copy link
Member

Probably it takes the first and last of the datetime in all your results values. If you don't think that is correct and it is not meeting what WaterML1_1 is supposed to do, please let me know and point me to the documentation of what is supposed to be there. Thanks.

@miguelcleon
Copy link
Member Author

Yeah it would make sense if it where finding the first and last datetime in the result values for the series but in this case it is not finding the correct beginDateTime. I checked in the database. actually you have a copy resultid 16664 if you want to look.

@lsetiawan
Copy link
Member

Okay, I will look into what's going on here. Thanks for letting me know.

@emiliom
Copy link
Member

emiliom commented Oct 20, 2017 via email

@lsetiawan
Copy link
Member

lsetiawan commented Oct 20, 2017

Hi All,

It seems like the values are grabbed from Action. https://github.com/ODM2/WOFpy/blob/master/wof/examples/flask/odm2/timeseries/sqlalch_odm2_models.py#L126

Here's what I get from debugging (All Action Instances)
BeginDateTime EndDateTime
2016-08-30 15:00:00 None
2014-03-10 09:00:00 None
2014-03-10 09:00:00 None
2014-03-10 09:00:00 None
2014-03-10 09:00:00 None
2016-08-30 15:00:00 None
2014-03-10 09:00:00 None
2014-03-10 09:00:00 None
2014-03-10 09:00:00 None

@lsetiawan
Copy link
Member

Though the end date is not any of those values... hmm...

@emiliom
Copy link
Member

emiliom commented Oct 20, 2017

Though the end date is not any of those values... hmm...

Well, see the logic starting on the next line:

if a_obj.EndDateTime is not None:
    self.EndDateTimeUTC = a_obj.EndDateTime.isoformat()
else:
    self.EndDateTimeUTC = r.tsrv_EndDateTime.isoformat()

A time series that's still ongoing (eg, sensor is still deployed) is supposed to have a NULL action EndDateTime; then, the response EndDateTime is grabbed from the actual time series result values. That's what the code is doing, so that part (end datetime) is working as intended.

Back to the BeginDateTime issue. @miguelcleon, I suspect what you're running into is not a WOFpy bug per se, but an ODM2 convention/expectation/best practice for time series results, that we (ODM2 gang) didn't make very obvious and you may not be following 😢. Namely, there is an action that corresponds to the current deployment of a sensor (result), and its BeginDateTime should be identical to the start of the time series. The alternative would be to query the time series result values to get the BeginDateTime, but we try to avoid doing that b/c it's a slow down on the WOFpy response. BUT, if you feel that would meet your needs better than the convention I've mentioned, you're free to customize your ODM2 time series DAO at exactly the line @lsetiawan pointed out! @lsetiawan can tell you if r (the results object referenced in r.tsrv_EndDateTime.isoformat()) already includes a r.tsrv_BeginDateTime; if it doesn't, the part of the DAO that queries the database would need to be tweaked. Even I can help you with that 😉

@lsetiawan
Copy link
Member

Well, see the logic starting on the next line:

Haha yea.. I remember that logic now! We put that in place 😄 Thanks @emiliom

@emiliom
Copy link
Member

emiliom commented Oct 20, 2017

A time series that's still ongoing (eg, sensor is still deployed) is supposed to have a NULL action EndDateTime; then, the response EndDateTime is grabbed from the actual time series result values. That's what the code is doing, so that part (end datetime) is working as intended.

I should add that the logic used in WOFpy can get tricky (ie, would need customization) if there's a chain of related actions during a sensor deployment. Or one can say, screw the attempt to minimize response times by leveraging actions, and just query the result values for both start and end datetimes to ensure accuracy!

@miguelcleon
Copy link
Member Author

@emiliom Yeah, I don't have an action for each sensor deployment. In most cases I have a generic sensor deployment action that is just serving to link the sampling feature and method. The funny thing is I'm actually going through a fair amount of trouble storing start and end dates in some result extension property values in ODM2 Admin. 😢

@emiliom
Copy link
Member

emiliom commented Oct 20, 2017

The funny thing is I'm actually going through a fair amount of trouble storing start and end dates in some result extension property values in ODM2 Admin

Well, the silver lining is that maybe you can customize your DAO to read from those result extension properties instead. I don't remember if odm2api already has a read service for result extension properties, but if it does, this may not be too much trouble (I can help next week, I think).

Then, let's discuss the broader issue of ODM2 conventions and challenges at the workshop, with a broader group! Maybe it's a good topic to discuss with everyone at the workshop, not just a small subset of people.

@miguelcleon
Copy link
Member Author

Yes, looks like it does. Yes, discussing conventions and challenges does sound like a good idea. I'll look into customizing the DAO.

@emiliom emiliom changed the title beginDateTime? Series beginDateTime source in ODM2 timeseries DAO? Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants