-
Notifications
You must be signed in to change notification settings - Fork 8
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
Tilføj tidsserie-modul (fire.api.ts) #547
base: master
Are you sure you want to change the base?
Conversation
Eksempel på anvendelse, som koden ser ud nu: from fire.api import ts
punkt_id = 'fb89d73a-c2a5-4fd6-974f-1fff650f5a66'
mulige = ts.hent_mulige_tidsserier(punkt_id)
mulige
# [('TS:81007', 11),
# ('EPSG:25832', 8),
# ('EPSG:4937', 7),
# ('EPSG:5799', 2),
# ('DK:S34S', 2),
# ('DK:GI44', 2),
# ('TS:BUDP', 1),
# ('EPSG:4258', 1)]
# Der er en tidsserie med SRID TS:81007
jessen_id = '81007'
tidsserie = ts.hent_tidsserie(jessen_id)
# Hent observationer fra opmålingsperiode ud fra punktgruppen i tidsserien
punktgruppe = sorted(set(tidsserie.punkt_id))
observationer_punktgruppe = ts.hent_observationer_af_punktgruppe(punktgruppe, dato_fra='2018-05-01', dato_til='2018-11-01')
# Hent observationer fra opmålingsperiode ud fra jessen_id (tidsserie-ID'et)
observationer_tidsserie = ts.hent_observationer_for_tidsserie(jessen_id, dato_fra='2018-05-01', dato_til='2018-11-01')
# Check, at de to resultatsæt er ens
all(observationer_punktgruppe == observationer_tidsserie)
# True
# Relativ kote
g = tidsserie
g['residual'] = g.kote - g[g.jessen_id == jessen_id].kote[0]
# Plot ...
# (...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lidt løse kommentarer. Ikke alle er reelt relevante på dette stadie i kodens udviklingshistorie, men måske anvendelige til overvejelse omkring den videre udvikling?
fire/api/ts/__init__.py
Outdated
return pd.DataFrame(columns=datacls.__annotations__).astype(datacls.__annotations__) | ||
|
||
|
||
def dataframe(datacls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smart!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pissesmart!!
fire/api/ts/__init__.py
Outdated
|
||
# --- TEMP | ||
|
||
# ENV_DB = 'test' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det ville väre rart med en kommentar her: Man skal helt ned og læse logikken i get_db()
før man kan se meningen
fire/api/ts/__init__.py
Outdated
# --- TEMP | ||
|
||
# ENV_DB = 'test' | ||
ENV_DB = 'prod' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENV_DB: Final = 'prod'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nå - jeg kan se at en kommentar oppe i toppen er drattet ud, med dekontekstualisering af denne kommentar til følge.
Det jeg mente var at typeannotationen Final
markerer en konstant. Final
bør derfor importeres sammen med Iterable
i dit from typing import
udtryk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, nice, den kendte jeg ikke... :)
fire/api/ts/__init__.py
Outdated
|
||
import datetime as dt | ||
from dataclasses import dataclass | ||
from typing import Iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det vil nok være en god idé også at importere Final
fra typing
, da du benytter konstanter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hov, nej, her kom den jo...
fire/api/ts/__init__.py
Outdated
|
||
# ENV_DB = 'test' | ||
ENV_DB = 'prod' | ||
DB = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fire/api/ts/__init__.py
Outdated
WHERE pit.infotype = 'IDENT:landsnr' | ||
) | ||
SELECT | ||
p.id AS punkt_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... og dog: Er dette rent faktisk en anvendelse, eller bare definition af en ny punkt_id
?
fire/api/ts/__init__.py
Outdated
k.t AS dato, | ||
k.z AS kote, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg er i hvert fald ret sikker på at disse to AS
ikke anvendes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@busstoptaktik selvom AS-aliasserne ikke nødvendigvis bruges direkte i SQL-koden kan det godt give mening. Det er også en måde at omdøbe kolonnerne i sit output, se fx her:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Praktisk!
fire/api/ts/__init__.py
Outdated
# return ny_df(TidsseriePost).append(data) # .astype(TidsseriePost) | ||
|
||
|
||
def hent_observationer_af_punktgruppe(punktgruppe: Iterable[str], dato_fra: dt.datetime = None, dato_til: dt.datetime = None, full_print: bool = False) -> pd.DataFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hent_observationer_i_punktgruppe
ville være et mere retvisende navn, da den enkelte observation er "i" og vi ikke altod har obs af hele gruppen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tak, jeg overvejede også semantikken til disse funktioner, men var ikke helt tilfreds. Jeg ser på det.
fire/api/ts/__init__.py
Outdated
* Punkgruppen er større end to punkter, da nedenstående forespørgsel ikke dur uden mindst to punkter, der er observeret mellem i løbet af det angivne tidsrum. | ||
""" | ||
# Start et halvt år tilbage, hvis én eller begge datoer i tidsrummet mangler. | ||
# TODO: Genbesøg detaljer, når resten er klar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
God idé :-)
fire/api/ts/__init__.py
Outdated
p.id = '{punkt_id}' | ||
""" | ||
print(sql) | ||
return fetchall(sql) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det ser ud som om der mangler et linjeskift her
Jeg undlader commits med ændringer til _netoversigt i den endelige rebase. |
Lige nu er det lidt svært at overskue koden her. Det ser ud som om der bliver foretaget to overordnede ting: 1) refaktorisering af regneark/dataframes og 2) tidsseriehåndtering. Måske det er en fordel at dele dem op i to separate pull requests? |
c5721ce
to
9d7e9e3
Compare
Tilføj udviklervenlige klasser, så vi har ét sted har de tekststrenge, der angiver kolonnerne i arkene. Undgår desuden run-time-fejl når de bruges i resten af koden.
… nyt modul fire.io.ts.post. Resten er tilhørende opdateringer.
Disse ændringer er indtil videre i draft-status.
Det skyldes, at arbejdet stadig pågår, herunder endelig brug af ændringer, som @kbevers har lavet til datamodellen, som betyder, at de eksplicitte SQL-forespørgsler i dette PR skal oversættes til tilsvarende ORM-forespørgsler.
Ændringerne i dette PR føjer følgende API til FIRE: