Replace 'CHANGE' database with 'STATE'

This commit is contained in:
coolneng 2020-01-06 11:12:55 +01:00
parent 6ef88e9b23
commit dfd13f6037
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
10 changed files with 21748 additions and 301841 deletions

View File

@ -56,7 +56,9 @@ CLOSED: [2020-01-03 Fri 00:44]
- [X] Convert PU to Country (ISO 3166) - [X] Convert PU to Country (ISO 3166)
- [ ] Arithmetic operations for yearly changes - [ ] Arithmetic operations for yearly changes
- [ ] Insert into database - [ ] Insert into database
**** NEXT Flask framework **** NEXT Flask framework [0/2] [0%]
-[[https://flask.palletsprojects.com/en/1.1.x/patterns/#patterns][ Patterns]] - [ ] Plots with pandas
- [ ] Login for admin
*** NEXT Documentation
*** INACTIVE Frontend [0/1] [0%] *** INACTIVE Frontend [0/1] [0%]
- [ ] [[https://adminlte.io/][Adminlte]] - [ ] [[https://adminlte.io/][Adminlte]]

View File

@ -45,14 +45,14 @@ class Annual_Data(db.Model):
db.Integer, db.ForeignKey("glacier.uid"), nullable=False, primary_key=True db.Integer, db.ForeignKey("glacier.uid"), nullable=False, primary_key=True
) )
surface = db.Column(db.Integer) surface = db.Column(db.Integer)
volume = db.Column(db.Integer) length = db.Column(db.Integer)
thickness = db.Column(db.Integer) elevation = db.Column(db.Integer)
year = db.Column(db.Integer, primary_key=True) year = db.Column(db.Integer, primary_key=True)
def __init__(self, surface, volume, thickness, year): def __init__(self, surface, length, elevation, year):
self.surface = surface self.surface = surface
self.volume = volume self.length = length
self.thickness = thickness self.elevation = elevation
self.year = year self.year = year
@ -62,14 +62,14 @@ class Annual_Change(db.Model):
db.Integer, db.ForeignKey("glacier.uid"), nullable=False, primary_key=True db.Integer, db.ForeignKey("glacier.uid"), nullable=False, primary_key=True
) )
surface_change = db.Column(db.Integer) surface_change = db.Column(db.Integer)
volume_change = db.Column(db.Integer) length_change = db.Column(db.Integer)
thickness_change = db.Column(db.Integer) elevation_change = db.Column(db.Integer)
year = db.Column(db.Integer, primary_key=True) year = db.Column(db.Integer, primary_key=True)
def __init__(self, surface_change, volume_change, thickness_change, year): def __init__(self, surface_change, length_change, elevation_change, year):
self.surface_change = surface_change self.surface_change = surface_change
self.volume_change = volume_change self.length_change = length_change
self.thickness_change = thickness_change self.elevation_change = elevation_change
self.year = year self.year = year

View File

@ -5,6 +5,8 @@ from constants import ADMIN_PW
def country_conversion(political_unit) -> str: def country_conversion(political_unit) -> str:
if political_unit == "99":
return "99"
codes = co.get(political_unit) codes = co.get(political_unit)
return codes.name return codes.name
@ -16,13 +18,12 @@ def select_columns() -> DataFrame:
"NAME", "NAME",
"WGMS_ID", "WGMS_ID",
"YEAR", "YEAR",
"AREA_SURVEY_YEAR", "MEDIAN_ELEVATION",
"AREA_CHANGE", "AREA",
"THICKNESS_CHG", "LENGTH",
"VOLUME_CHANGE",
] ]
iter_csv = read_csv( iter_csv = read_csv(
"../data/WGMS-FoG-2019-12-D-CHANGE.csv", "../data/WGMS-FoG-2019-12-B-STATE.csv",
skipinitialspace=True, skipinitialspace=True,
usecols=fields, usecols=fields,
iterator=True, iterator=True,
@ -37,16 +38,14 @@ def create_databases(df):
users = {"UID": [7843], "USERNAME": ["admin"], "PASSWORD": [ADMIN_PW]} users = {"UID": [7843], "USERNAME": ["admin"], "PASSWORD": [ADMIN_PW]}
files = { files = {
"glacier": "../data/glacier.csv", "glacier": "../data/glacier.csv",
"annual_data": "../data/annual_data.csv", "annual__data": "../data/annual_data.csv",
"annual_change": "../data/annual_change.csv", "annual__change": "../data/annual_change.csv",
"users": "../data/users.csv", "users": "../data/users.csv",
} }
dataframes = { dataframes = {
"glacier": df[["POLITICAL_UNIT", "NAME", "WGMS_ID"]].drop_duplicates(), "glacier": df[["POLITICAL_UNIT", "NAME", "WGMS_ID"]].drop_duplicates(),
"annual_data": df[["WGMS_ID", "YEAR", "AREA_SURVEY_YEAR"]], "annual__data": df[["WGMS_ID", "YEAR", "AREA", "MEDIAN_ELEVATION", "LENGTH"]],
"annual_change": df[ "annual__change": df[["WGMS_ID", "YEAR"]],
["WGMS_ID", "YEAR", "AREA_CHANGE", "THICKNESS_CHG", "VOLUME_CHANGE"]
],
"users": DataFrame(users), "users": DataFrame(users),
} }
for key, val in dataframes.items(): for key, val in dataframes.items():

View File

@ -2,20 +2,28 @@ from db_setup import create_connection
from pandas import DataFrame, read_csv, to_sql from pandas import DataFrame, read_csv, to_sql
def create_dataframe() -> DataFrame: def create_dataframes() -> DataFrame:
csv_file = "../data/igdb.csv" files = {
df = read_csv(csv_file) "glacier": "../data/glacier.csv",
return df "annual__data": "../data/annual_data.csv",
"annual__change": "../data/annual_change.csv",
"users": "../data/users.csv",
}
df_list = {}
for csv in files.keys():
df_list[csv] = read_csv(files[csv], index=False)
return df_list
def insert_data(df, conn): def insert_data(df_list, conn):
df.to_sql("glacier", con=conn, if_exists="replace", index=False) for key, value in df_list.items():
value.to_sql(key, con=conn, if_exists="replace", index=False)
def main(): def main():
conn = create_connection() conn = create_connection()
df = create_dataframe() df_list = create_dataframes()
insert_data(df, conn) insert_data(df_list, conn)
if __name__ == "__main__": if __name__ == "__main__":

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -26,14 +26,14 @@ datos relevantes para estudios acerca del cambio climático, y acotando éstos a
- ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/ - ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/
- Área - /Entero de 10 dígitos/ - Área - /Entero de 10 dígitos/
- Volumen - /Entero de 10 dígitos/ - Volumen - /Entero de 10 dígitos/
- Grosor - /Entero de 10 dígitos/ - Altura - /Entero de 10 dígitos/
- Año - /Entero de 10 dígitos/ - Año - /Entero de 10 dígitos/
3. *RD3*: Datos de cambio de un glaciar 3. *RD3*: Datos de cambio de un glaciar
- ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/ - ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/
- Variación de área - /Entero de 10 dígitos/ - Variación de área - /Entero de 10 dígitos/
- Variación de volumen - /Entero de 10 dígitos/ - Variación de volumen - /Entero de 10 dígitos/
- Variación de grosor - /Entero de 10 dígitos/ - Variación de altura - /Entero de 10 dígitos/
- Año - /Entero de 10 dígitos/ - Año - /Entero de 10 dígitos/
4. *RD4*: Datos del administrador 4. *RD4*: Datos del administrador
@ -56,7 +56,7 @@ datos relevantes para estudios acerca del cambio climático, y acotando éstos a
3. *RF3*: Cálculo de las variaciones anuales 3. *RF3*: Cálculo de las variaciones anuales
Calcula las variaciones anuales de grosor, área y volumen para un glaciar Calcula las variaciones anuales de altura, área y longitud para un glaciar
- Entrada: *RD2* - Entrada: *RD2*
- Manejo: *RD3* - Manejo: *RD3*