Пример #1
0
def get_model_to_dict_dates(m, project_db):
    d = model_to_dict(m)
    d["reference_db"] = utils.full_path(project_db, m.reference_db)
    d["wgn_db"] = utils.full_path(project_db, m.wgn_db)
    d["weather_data_dir"] = utils.full_path(project_db, m.weather_data_dir)
    d["input_files_dir"] = utils.full_path(project_db, m.input_files_dir)
    d["input_files_last_written"] = utils.json_encode_datetime(
        m.input_files_last_written)
    d["swat_last_run"] = utils.json_encode_datetime(m.swat_last_run)
    d["output_last_imported"] = utils.json_encode_datetime(
        m.output_last_imported)
    return d
Пример #2
0
 def get(self, project_db):
     SetupProjectDatabase.init(project_db)
     try:
         m = Project_config.get()
         return {
             "has_weather":
             climate.Weather_sta_cli.select().count() > 0
             and climate.Weather_wgn_cli.select().count() > 0,
             "input_files_dir":
             utils.full_path(project_db, m.input_files_dir),
             "input_files_last_written":
             utils.json_encode_datetime(m.input_files_last_written),
             "swat_last_run":
             utils.json_encode_datetime(m.swat_last_run)
         }
     except Project_config.DoesNotExist:
         abort(404,
               message="Could not retrieve project configuration data.")
Пример #3
0
    def get(self, project_db):
        SetupProjectDatabase.init(project_db)

        conn = lib.open_db(project_db)
        if not lib.exists_table(conn, 'chandeg_con'):
            abort(400, message='Project has not been set up.')

        try:
            m = Project_config.get()

            gis_type = 'QSWAT+ ' if m.gis_type == 'qgis' else 'GIS '
            gis_text = '' if m.gis_version is None else gis_type + m.gis_version

            landuse_distrib = []
            if m.gis_version is not None:
                landuse_distrib = gis.Gis_hrus.select(
                    fn.Lower(gis.Gis_hrus.landuse).alias('name'),
                    fn.Sum(gis.Gis_hrus.arslp).alias('y')).group_by(
                        gis.Gis_hrus.landuse)

            current_path = os.path.dirname(project_db)
            scenarios_path = os.path.join(current_path, 'Scenarios')
            scenarios = []
            if os.path.isdir(scenarios_path):
                for p in os.listdir(scenarios_path):
                    if os.path.isdir(os.path.join(
                            scenarios_path,
                            p)) and p != 'Default' and p != 'default':
                        db_files = [
                            f for f in os.listdir(
                                os.path.join(scenarios_path, p))
                            if f.endswith('.sqlite')
                        ]
                        if len(db_files) > 0:
                            scenarios.append({
                                'name':
                                p,
                                'path':
                                os.path.join(scenarios_path, p, db_files[0])
                            })

            oc = Object_cnt.get_or_none()

            info = {
                'name':
                m.project_name,
                'description':
                oc.name,
                'file_path':
                current_path,
                'last_modified':
                utils.json_encode_datetime(
                    datetime.fromtimestamp(os.path.getmtime(project_db))),
                'is_lte':
                m.is_lte,
                'status': {
                    'imported_weather':
                    climate.Weather_sta_cli.select().count() > 0
                    and climate.Weather_wgn_cli.select().count() > 0,
                    'wrote_inputs':
                    m.input_files_last_written is not None,
                    'ran_swat':
                    m.swat_last_run is not None,
                    'imported_output':
                    m.output_last_imported is not None,
                    'using_gis':
                    m.gis_version is not None
                },
                'simulation':
                model_to_dict(simulation.Time_sim.get_or_none()),
                'total_area':
                connect.Rout_unit_con.
                select(fn.Sum(connect.Rout_unit_con.area)).scalar(
                ),  #gis.Gis_subbasins.select(fn.Sum(gis.Gis_subbasins.area)).scalar(),
                'totals': {
                    'hru': connect.Hru_con.select().count(),
                    'lhru': connect.Hru_lte_con.select().count(),
                    'rtu': connect.Rout_unit_con.select().count(),
                    'mfl': connect.Modflow_con.select().count(),
                    'aqu': connect.Aquifer_con.select().count(),
                    'cha': connect.Channel_con.select().count(),
                    'res': connect.Reservoir_con.select().count(),
                    'rec': connect.Recall_con.select().count(),
                    'exco': connect.Exco_con.select().count(),
                    'dlr': connect.Delratio_con.select().count(),
                    'out': connect.Outlet_con.select().count(),
                    'lcha': connect.Chandeg_con.select().count(),
                    'aqu2d': connect.Aquifer2d_con.select().count(),
                    'lsus': regions.Ls_unit_def.select().count(),
                    'subs': gis.Gis_subbasins.select().count()
                },
                'editor_version':
                m.editor_version,
                'gis_version':
                gis_text,
                'charts': {
                    'landuse': [{
                        'name': o.name,
                        'y': o.y
                    } for o in landuse_distrib]
                },
                'scenarios':
                scenarios
            }

            return info
        except Project_config.DoesNotExist:
            abort(404,
                  message="Could not retrieve project configuration data.")