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)
- [ ] Arithmetic operations for yearly changes
- [ ] Insert into database
**** NEXT Flask framework
-[[https://flask.palletsprojects.com/en/1.1.x/patterns/#patterns][ Patterns]]
**** NEXT Flask framework [0/2] [0%]
- [ ] Plots with pandas
- [ ] Login for admin
*** NEXT Documentation
*** INACTIVE Frontend [0/1] [0%]
- [ ] [[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
)
surface = db.Column(db.Integer)
volume = db.Column(db.Integer)
thickness = db.Column(db.Integer)
length = db.Column(db.Integer)
elevation = db.Column(db.Integer)
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.volume = volume
self.thickness = thickness
self.length = length
self.elevation = elevation
self.year = year
@ -62,14 +62,14 @@ class Annual_Change(db.Model):
db.Integer, db.ForeignKey("glacier.uid"), nullable=False, primary_key=True
)
surface_change = db.Column(db.Integer)
volume_change = db.Column(db.Integer)
thickness_change = db.Column(db.Integer)
length_change = db.Column(db.Integer)
elevation_change = db.Column(db.Integer)
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.volume_change = volume_change
self.thickness_change = thickness_change
self.length_change = length_change
self.elevation_change = elevation_change
self.year = year

View File

@ -5,6 +5,8 @@ from constants import ADMIN_PW
def country_conversion(political_unit) -> str:
if political_unit == "99":
return "99"
codes = co.get(political_unit)
return codes.name
@ -16,13 +18,12 @@ def select_columns() -> DataFrame:
"NAME",
"WGMS_ID",
"YEAR",
"AREA_SURVEY_YEAR",
"AREA_CHANGE",
"THICKNESS_CHG",
"VOLUME_CHANGE",
"MEDIAN_ELEVATION",
"AREA",
"LENGTH",
]
iter_csv = read_csv(
"../data/WGMS-FoG-2019-12-D-CHANGE.csv",
"../data/WGMS-FoG-2019-12-B-STATE.csv",
skipinitialspace=True,
usecols=fields,
iterator=True,
@ -37,16 +38,14 @@ def create_databases(df):
users = {"UID": [7843], "USERNAME": ["admin"], "PASSWORD": [ADMIN_PW]}
files = {
"glacier": "../data/glacier.csv",
"annual_data": "../data/annual_data.csv",
"annual_change": "../data/annual_change.csv",
"annual__data": "../data/annual_data.csv",
"annual__change": "../data/annual_change.csv",
"users": "../data/users.csv",
}
dataframes = {
"glacier": df[["POLITICAL_UNIT", "NAME", "WGMS_ID"]].drop_duplicates(),
"annual_data": df[["WGMS_ID", "YEAR", "AREA_SURVEY_YEAR"]],
"annual_change": df[
["WGMS_ID", "YEAR", "AREA_CHANGE", "THICKNESS_CHG", "VOLUME_CHANGE"]
],
"annual__data": df[["WGMS_ID", "YEAR", "AREA", "MEDIAN_ELEVATION", "LENGTH"]],
"annual__change": df[["WGMS_ID", "YEAR"]],
"users": DataFrame(users),
}
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
def create_dataframe() -> DataFrame:
csv_file = "../data/igdb.csv"
df = read_csv(csv_file)
return df
def create_dataframes() -> DataFrame:
files = {
"glacier": "../data/glacier.csv",
"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):
df.to_sql("glacier", con=conn, if_exists="replace", index=False)
def insert_data(df_list, conn):
for key, value in df_list.items():
value.to_sql(key, con=conn, if_exists="replace", index=False)
def main():
conn = create_connection()
df = create_dataframe()
insert_data(df, conn)
df_list = create_dataframes()
insert_data(df_list, conn)
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/
- Área - /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/
3. *RD3*: Datos de cambio de un glaciar
- ID del glaciar (Compatible con la WGMS) - /Entero de 5 dígitos/
- Variación de área - /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/
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
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*
- Manejo: *RD3*