-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
82 lines (73 loc) · 2.44 KB
/
utils.py
File metadata and controls
82 lines (73 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
###
# Copyright 2021, ISB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
# from flask import Flask, render_template, request, send_from_directory, json, jsonify, make_response
# from google.cloud import bigquery
# from google.api_core.exceptions import BadRequest
# import concurrent.futures
# import requests
# import sys
# import copy
import os
import csv
import json
# from io import StringIO
def load_topo_morph_assc(json_file, base_url):
topo_morph_map = {}
try:
file_path = base_url + "/list-files/" + json_file
with open(file_path) as file:
data = json.load(file)
for row in data:
topo = row["Short_topo"]
morph = row["Morphology"]
if topo not in topo_morph_map.keys():
topo_morph_map[topo] = []
topo_morph_map[topo].append(morph)
del data
except:
print("Error while loading " + json_file)
return topo_morph_map
def load_list(list_file, base_url, limit=None):
data_list = []
try:
file_path = base_url + "/list-files/" + list_file
data_list = []
with open(file_path) as file:
if os.path.splitext(list_file)[1] == ".json":
data_list = json.load(file)
else:
lines = file.readlines()
if limit:
lines = lines[0:limit]
for line in lines:
data_list.append({"label": line.strip()})
except:
data_list = []
return data_list
def load_csv_file(base_url, list_file):
column_list = []
data_list = []
try:
file_path = base_url + "/data/" + list_file
with open(file_path, "r", encoding="utf-8") as file:
reader = csv.reader(file, delimiter=",")
column_list = next(reader)
data_list = list(reader)
for row in data_list:
row.insert(0, "")
except:
data_list = []
return column_list, data_list