def openQuery(station_id, year): query = am.Query( where=f"sample_date>=01.01.{year} and sample_date<=31.12.{year}", stations=[station_id], table="water_chemistry_input") query.createQuery() return query.key
def insertValues(original, method_id, pairs): for value in am.Query(key=key).list(): for pair in pairs: if value["Method"]["Name"] == original \ and value["Sample"]["SampleDate"] == pair["Date"]: if value["Approved"]: value["Approved"] = False value["Remark"] = "OKA: Erstattet med korrigert verdi" print( am.putJson( token, am.aqua_site + f"/api/waterchemistry/{value['Id']}", value)) #print(value) new_value = { "Sample": { "Id": value["Sample"]["Id"] }, "Method": { "Id": method_id }, "Value": pair["Value"], "Approved": True } print( am.postJson(token, am.aqua_site + "/api/waterchemistry", new_value))
def approveValues(name, dates): for value in filter( lambda wc: wc["Method"]["Name"] == name and wc["Sample"][ "SampleDate"] in dates, am.Query(key=key).list()): value["Approved"] = True value["Remark"] = "" am.putJson(token, am.aqua_site + f"/api/waterchemistry/{value['Id']}", value) print(value)
def disapproveValues(name, dates): for value in filter( lambda wc: wc["Method"]["Name"] == name and wc["Sample"]["Depth1"] == 1 and wc["Sample"]["Depth2"] == 1 and wc["Sample"]["SampleDate" ] in dates, am.Query(key=key).map()): if value["Approved"]: value["Approved"] = False value["Remark"] = "OKA: Tas ut" print( am.putJson(token, am.aqua_site + f"/api/waterchemistry/{value['Id']}", value))
def generate_map(stationId): result = am.Query("station_id = " + str(stationId), table="Metadata").list() print(result.pages) for i in range(result.pages): meta = result.fetch(i) for m in meta: sid = m["_Id"] lon = m["_Longitude"] lat = m["_Latitude"] if lon > 24: epsg = 32635 elif lon > 18: epsg = 32634 elif lon > 12: epsg = 32633 else: epsg = 32632 x, y = transform(Proj(init="epsg:4326"), Proj(init="epsg:" + str(epsg)), lon, lat) bbox = str(x - 3000) + "," + str(y - 3000) + "," + str( x + 3000) + "," + str(y + 3000) width = 300 height = 300 resp = requests.get( geoserverUrl + "/wms?" + "service=WMS&version=1.1.0&request=GetMap&" + "layers=no.norgedigitalt:kartdata,no.niva.aquamonitor:Innsjo_stations&" + "styles=,&bbox=" + bbox + "&width=" + str(width) + "&height=" + str(height) + "&srs=EPSG:" + str(epsg) + "&format=image%2Fpng", stream=True, auth=("aquamonitor", "trommer")) if resp.status_code == 200: with open("C:/Innsjo2019/kart/" + str(sid) + ".png", "wb") as f: for chunk in resp: f.write(chunk) else: print("Id:" + str(sid) + " error code:" + str(resp.status_code))
def download_am_file(): am.Query("project_id=" + str(projectInnsjo2019))\ .makeArchive("excel", "am1000sjoer.xlsx")\ .download("c:/Innsjo2019/")
__author__ = 'Roar Brenden' import aquamonitor as am token = am.login() site = "mjosovervak" where = "project_id=1098 and sample_date>01.01.2020 and sample_date<=31.12.2020 and Plankton.parameter_id=2" width = 650 height = 300 root = "C:/temp/" for station_id in am.Query(where=where).list(): file = root + "plankton_" + str(station_id) + ".png" am.Graph(width, height, token=token, site=site, graph='/Graph/Stolpediagram.ashx', stationId=station_id, parameter='Plankton;2', where=where)\ .download(file)
# Test #am.host = "https://test-aquamonitor.niva.no/" #list = am.Query("project_id = 9566").list() #print(list) #gl_params = [] # stations = am.Query("project_id = 86 and sample_date > 01.01.1990 and sample_date <= 31.12.2016 and datatype=Plankton")\ # .map("Stations") # for stat in stations: # print(stat) #am.Query("project_id = 9566 and sample_date > 01.01.2016 and sample_date <= 31.12.2016")\ # .makeArchive("excel", "Mjosa_2016.xlsx")\ # .download("/Users/roar/Mjosa/") pages = am.Query("project_id = 12433 and sample_date > 01.01.2019 and sample_date <= 31.12.2019", table="water_chemistry_output")\ .pages() print(pages.total) # # This is the result of the call for query/{key}/water_chemistry_output # The resultset can be obtained by iterating over all the pages given by chemistry.Pages # The path for a page would be query/{key}/water_chemistry_output/{page} # Page is 0-based # The key is hidden within AquaMonitor.Query.key tenth = pages.fetch(9) print(tenth)
def filterMethod(key, name): return filter(lambda c: c["Method"]["Name"] == name, am.Query(key=key).map())
def printQuery(key): am.Query(key=key).map(print)