11import csv
22import gzip
33import threading
4+ import typing
45from queue import Queue
56
67from osgeo import ogr
@@ -16,6 +17,21 @@ def load_data(project_id: str, gzipped_csv_file: str) -> list:
1617 maybe_share and wkt
1718 """
1819
20+ def _get_row_value (
21+ column_index_map : dict ,
22+ row : list ,
23+ label : str ,
24+ default : int = 0 ,
25+ modifier : typing .Callable = int ,
26+ ):
27+ """
28+ Get row value by using column name.
29+ """
30+ if label not in column_index_map :
31+ return modifier (default )
32+ index = column_index_map [label ]
33+ return modifier (row [index ])
34+
1935 project_data = []
2036 with gzip .open (gzipped_csv_file , mode = "rt" ) as f :
2137 reader = csv .reader (f , delimiter = "," )
@@ -47,14 +63,24 @@ def load_data(project_id: str, gzipped_csv_file: str) -> list:
4763 "task_y" : task_y ,
4864 "task_z" : task_z ,
4965 # XXX: Assuming 0->No, 1->Yes, 2->Maybe, 3->Bad
50- "no_count" : int (column_index_map .get ("0_count" , 0 )),
51- "yes_count" : int (column_index_map .get ("1_count" , 0 )),
52- "maybe_count" : int (column_index_map .get ("2_count" , 0 )),
53- "bad_imagery_count" : int (column_index_map .get ("3_count" , 0 )),
54- "no_share" : float (column_index_map .get ("0_share" , 0 )),
55- "yes_share" : float (column_index_map .get ("1_share" , 0 )),
56- "maybe_share" : float (column_index_map .get ("2_share" , 0 )),
57- "bad_imagery_share" : float (column_index_map .get ("3_share" , 0 )),
66+ "no_count" : _get_row_value (column_index_map , row , "0_count" ),
67+ "yes_count" : _get_row_value (column_index_map , row , "1_count" ),
68+ "maybe_count" : _get_row_value (column_index_map , row , "2_count" ),
69+ "bad_imagery_count" : _get_row_value (
70+ column_index_map , row , "3_count"
71+ ),
72+ "no_share" : _get_row_value (
73+ column_index_map , row , "0_share" , modifier = float
74+ ),
75+ "yes_share" : _get_row_value (
76+ column_index_map , row , "1_share" , modifier = float
77+ ),
78+ "maybe_share" : _get_row_value (
79+ column_index_map , row , "2_share" , modifier = float
80+ ),
81+ "bad_imagery_share" : _get_row_value (
82+ column_index_map , row , "3_share" , modifier = float
83+ ),
5884 "wkt" : tile_functions .geometry_from_tile_coords (
5985 task_x , task_y , task_z
6086 ),
0 commit comments