Skip to content

Commit 637f83d

Browse files
committed
flake8
1 parent 9b4ff29 commit 637f83d

12 files changed

Lines changed: 50 additions & 47 deletions

allocator/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def setup_logging(level=logging.INFO):
1010
"""
1111
Set up logging configuration for the allocator package.
12-
12+
1313
Args:
1414
level: Logging level (DEBUG, INFO, WARNING, ERROR)
1515
"""
@@ -18,36 +18,36 @@ def setup_logging(level=logging.INFO):
1818
'%(asctime)s - %(name)s - %(levelname)s - %(message)s',
1919
datefmt='%Y-%m-%d %H:%M:%S'
2020
)
21-
21+
2222
# Get root logger for allocator package
2323
logger = logging.getLogger('allocator')
2424
logger.setLevel(level)
25-
25+
2626
# Remove existing handlers to avoid duplicates
2727
for handler in logger.handlers[:]:
2828
logger.removeHandler(handler)
29-
29+
3030
# Console handler
3131
console_handler = logging.StreamHandler(sys.stdout)
3232
console_handler.setLevel(level)
3333
console_handler.setFormatter(formatter)
3434
logger.addHandler(console_handler)
35-
35+
3636
return logger
3737

3838

3939
def get_logger(name):
4040
"""
4141
Get a logger instance for a specific module.
42-
42+
4343
Args:
4444
name: Module name (typically __name__)
45-
45+
4646
Returns:
4747
Logger instance
4848
"""
4949
return logging.getLogger(f'allocator.{name}')
5050

5151

5252
# Set up default logging
53-
setup_logging()
53+
setup_logging()

allocator/cluster_kahip.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def main(argv=sys.argv[1:]):
102102
sys.exit(-1)
103103
distances = google_distance_matrix(X, api_key=args.api_key,
104104
duration=False)
105-
105+
106106
if distances is None:
107107
print("ERROR: Couldn't get distance matrix of locations")
108108
sys.exit(-2)
@@ -131,7 +131,11 @@ def main(argv=sys.argv[1:]):
131131

132132
os.putenv('LD_LIBRARY_PATH', os.path.join(args.kahip_dir, 'extern/argtable-2.10/lib'))
133133

134-
buffoon_cmd = 'mpirun -n {k:d} {base:s}/optimized/buffoon metis.graph --seed {seed:d} --k {k:d} --preconfiguration=strong --max_num_threads={k:d}'.format(k=n_clusters, base=args.kahip_dir, seed=seed)
134+
buffoon_cmd = ('mpirun -n {k:d} {base:s}/optimized/buffoon metis.graph '
135+
'--seed {seed:d} --k {k:d} --preconfiguration=strong '
136+
'--max_num_threads={k:d}').format(k=n_clusters,
137+
base=args.kahip_dir,
138+
seed=seed)
135139

136140
print(("Command line: '{:s}'".format(buffoon_cmd)))
137141

@@ -222,5 +226,6 @@ def main(argv=sys.argv[1:]):
222226
odf.to_csv(args.output, index=False)
223227
print("Done")
224228

229+
225230
if __name__ == "__main__":
226231
sys.exit(main())

allocator/cluster_kmeans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def main(argv=sys.argv[1:]):
105105
closest_func = {'euclidean': closest_centroid_euclidean,
106106
'haversine': closest_centroid_haversine,
107107
'osrm': lambda A, B:
108-
closest_centroid_osrm(A, B, args)}
108+
closest_centroid_osrm(A, B, args)}
109109

110110
X = df[['start_long', 'start_lat']].values
111111

allocator/compare_kahip_kmeans.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def main(argv=sys.argv[1:]):
7272
bdf = pd.read_csv('tmpkahip{k:d}.csv'.format(k=n_clusters))
7373

7474
buffoon_w = []
75-
for l in sorted(bdf.assigned_points.unique()):
76-
X = bdf.loc[bdf.assigned_points == l, ['start_long', 'start_lat']].values
75+
for cluster_id in sorted(bdf.assigned_points.unique()):
76+
X = bdf.loc[bdf.assigned_points == cluster_id, ['start_long', 'start_lat']].values
7777
n = len(X)
7878
if args.distance_func == 'euclidean':
7979
distances = euclidean_distance_matrix(X)
@@ -87,7 +87,7 @@ def main(argv=sys.argv[1:]):
8787
T = nx.minimum_spanning_tree(G)
8888
gw = int(G.size(weight='weight') / 1000)
8989
tw = int(T.size(weight='weight') / 1000)
90-
buffoon_w.append([l, n, gw, tw])
90+
buffoon_w.append([cluster_id, n, gw, tw])
9191

9292
adf = pd.DataFrame(buffoon_w, columns=['label', 'n', 'graph_weight',
9393
'mst_weight'])
@@ -103,8 +103,8 @@ def main(argv=sys.argv[1:]):
103103
kdf = pd.read_csv('tmpkmean{k:d}.csv'.format(k=n_clusters))
104104

105105
kmean_w = []
106-
for l in sorted(kdf.assigned_points.unique()):
107-
X = kdf.loc[kdf.assigned_points == l, ['start_long', 'start_lat']].values
106+
for cluster_id in sorted(kdf.assigned_points.unique()):
107+
X = kdf.loc[kdf.assigned_points == cluster_id, ['start_long', 'start_lat']].values
108108
n = len(X)
109109
if args.distance_func == 'euclidean':
110110
distances = euclidean_distance_matrix(X)
@@ -118,7 +118,7 @@ def main(argv=sys.argv[1:]):
118118
T = nx.minimum_spanning_tree(G)
119119
gw = int(G.size(weight='weight') / 1000)
120120
tw = int(T.size(weight='weight') / 1000)
121-
kmean_w.append([l, n, gw, tw])
121+
kmean_w.append([cluster_id, n, gw, tw])
122122

123123
bdf = pd.DataFrame(kmean_w, columns=['label', 'n', 'graph_weight',
124124
'mst_weight'])

allocator/distance_matrix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import time
88

99
import numpy as np
10-
11-
from allocator import get_logger
12-
logger = get_logger(__name__)
1310
import requests
1411
import googlemaps
1512
import utm
1613

1714
from haversine import haversine
15+
from allocator import get_logger
16+
17+
logger = get_logger(__name__)
1818

1919

2020
MAX_DISTANCE_MATRIX_SIZE = 100

allocator/shortest_path_gm.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
import os
99
import sys
1010
import argparse
11-
1211
from random import randint
1312

1413
import pandas as pd
14+
import googlemaps
15+
import polyline
1516

1617
from allocator import get_logger
17-
logger = get_logger(__name__)
1818

19-
import googlemaps
20-
import polyline
19+
logger = get_logger(__name__)
2120

2221

2322
def main(argv=sys.argv[1:]):
@@ -75,9 +74,9 @@ def main(argv=sys.argv[1:]):
7574
waypoints = [', '.join([str(x) for x in n]) for n in nodes[1:]]
7675
try:
7776
routes = gmaps.directions(start,
78-
start,
79-
waypoints=waypoints,
80-
optimize_waypoints=True)
77+
start,
78+
waypoints=waypoints,
79+
optimize_waypoints=True)
8180
for x in routes:
8281
rp = x['overview_polyline']['points']
8382
points = polyline.decode(rp)

allocator/shortest_path_ortools.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88
import os
99
import sys
1010
import argparse
11+
from random import randint
1112

1213
import pandas as pd
1314

14-
from allocator import get_logger
15-
logger = get_logger(__name__)
16-
17-
from random import randint
18-
1915
from ortools.constraint_solver import pywrapcp
2016
# You need to import routing_enums_pb2 after pywrapcp!
2117
from ortools.constraint_solver import routing_enums_pb2
2218

19+
from allocator import get_logger
2320
from allocator.distance_matrix import (euclidean_distance_matrix,
2421
haversine_distance_matrix,
2522
osrm_distance_matrix)
2623

24+
logger = get_logger(__name__)
25+
2726

2827
class DistanceMatrix(object):
2928
"""Random matrix."""

allocator/shortest_path_osrm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import argparse
1111

1212
import pandas as pd
13+
import requests
14+
import polyline
1315

1416
from allocator import get_logger
15-
logger = get_logger(__name__)
1617

17-
import requests
18-
import polyline
18+
logger = get_logger(__name__)
1919

2020

2121
def osrm_trip(coords, osrm_base_url=None):

allocator/sort_by_distance.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main(argv=sys.argv[1:]):
7979
sys.exit(-1)
8080
distances = google_distance_matrix(X, centroids,
8181
args.api_key, duration=False)
82-
82+
8383
if distances is None:
8484
print("ERROR: Couldn't get distance matrix of locations")
8585
sys.exit(-2)
@@ -123,13 +123,13 @@ def main(argv=sys.argv[1:]):
123123

124124
if args.by_worker:
125125
output = []
126-
for l in sorted(df['assigned_points'].unique()):
127-
colname = 'distance_{:d}'.format(l)
128-
xdf = df[df.assigned_points == l][['segment_id', colname]]
126+
for worker_id in sorted(df['assigned_points'].unique()):
127+
colname = 'distance_{:d}'.format(worker_id)
128+
xdf = df[df.assigned_points == worker_id][['segment_id', colname]]
129129
xdf.reset_index(drop=True, inplace=True)
130130
points = xdf.loc[np.argsort(xdf[colname]),
131131
'segment_id'].astype(str).tolist()
132-
output.append([l, ';'.join(points)])
132+
output.append([worker_id, ';'.join(points)])
133133
odf = pd.DataFrame(output, columns=['worker_id', 'segment_ids'])
134134
odf.to_csv(args.output, index=False)
135135
else:

allocator/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from contextlib import contextmanager
33
try:
44
from io import StringIO
5-
except:
5+
except ImportError:
66
from io import StringIO
77

88

0 commit comments

Comments
 (0)