Commit ed453065626393e53b2a2c6b705a10879be50ec5

Authored by hitier
1 parent 854e5e73

Remove empty values, and upper() some lists

Showing 1 changed file with 21 additions and 11 deletions   Show diff stats
app/commands/commands.py
... ... @@ -57,8 +57,6 @@ def feed_from_irap(csv_file_name):
57 57 with open(csv_file_name, newline='') as csvfile:
58 58 csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
59 59 for row in csvreader:
60   - # print('\n'.join(row.keys()))
61   - # break
62 60 # Remove any leading/trailing spaces
63 61 row = {k: v.strip() for k, v in row.items()}
64 62 rows.append(row)
... ... @@ -105,16 +103,26 @@ def feed_from_irap(csv_file_name):
105 103 'grade': r[grade_key]}
106 104 agents.append(agent_dict)
107 105  
108   - # Now, uniq/sort the lists
  106 + # Uppercase the small tables
  107 + #
  108 + baps = [x.upper() for x in baps]
  109 + grades = [x.upper() for x in grades]
  110 + statuses = [x.upper() for x in statuses]
  111 +
  112 + # Now, sort the lists
  113 + #
  114 + # 1- first remove empty string with filter()
  115 + # 2- then keep only uniq item with set()
  116 + # 3- at last alpha sort with sorted()
109 117 #
110 118 # thematics = sorted(set(thematics))
111 119 # typologies = sorted(set(typologies))
112   - projects = sorted(set(projects))
113   - services = sorted(set(services))
114   - baps = sorted(set(baps))
115   - grades = sorted(set(grades))
116   - companies = sorted(set(companies))
117   - statuses = sorted(set(statuses))
  120 + projects = sorted(set(filter(None, projects)))
  121 + services = sorted(set(filter(None, services)))
  122 + baps = sorted(set(filter(None, baps)))
  123 + grades = sorted(set(filter(None, grades)))
  124 + companies = sorted(set(filter(None, companies)))
  125 + statuses = sorted(set(filter(None, statuses)))
118 126  
119 127 # as agents is a list of dicts, sorting is a bit tricky
120 128 #
... ... @@ -169,7 +177,8 @@ def feed_from_irap(csv_file_name):
169 177  
170 178 # Feed periods names
171 179 # Todo: are statically built,
172   - # should come from year column name.
  180 + # should come from year column name.
  181 + # also see later
173 182 #
174 183 for p in range(2011, 2030):
175 184 n_p = Period(name=f"{p}")
... ... @@ -201,7 +210,7 @@ def feed_from_irap(csv_file_name):
201 210 status_id=status.id if status else None,
202 211 company_id=company.id if company else None,
203 212 bap_id=bap.id if bap else None,
204   - grade_id=grade.id if bap else None,
  213 + grade_id=grade.id if grade else None,
205 214 virtual=virtual)
206 215 db.session.add(n_a)
207 216 db.session.commit()
... ... @@ -216,6 +225,7 @@ def feed_from_irap(csv_file_name):
216 225 a = Agent.query.filter(Agent.firstname == r[firstname_key], Agent.secondname == r[secondname_key]).one()
217 226 s = Service.query.filter(Service.name == r[service_key]).one()
218 227 c = Capacity.query.first()
  228 + # TODO: period names should come from db request
219 229 for period_name in range(2011, 2030):
220 230 t = Period.query.filter(Period.name == period_name).one()
221 231 charge = r[f"{period_name}"]
... ...