1
1
import csv
2
2
import gzip
3
3
import threading
4
+ import typing
4
5
from queue import Queue
5
6
6
7
from osgeo import ogr
@@ -16,6 +17,21 @@ def load_data(project_id: str, gzipped_csv_file: str) -> list:
16
17
maybe_share and wkt
17
18
"""
18
19
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
+
19
35
project_data = []
20
36
with gzip .open (gzipped_csv_file , mode = "rt" ) as f :
21
37
reader = csv .reader (f , delimiter = "," )
@@ -47,14 +63,24 @@ def load_data(project_id: str, gzipped_csv_file: str) -> list:
47
63
"task_y" : task_y ,
48
64
"task_z" : task_z ,
49
65
# 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
+ ),
58
84
"wkt" : tile_functions .geometry_from_tile_coords (
59
85
task_x , task_y , task_z
60
86
),
0 commit comments