-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrix1to2.py
47 lines (34 loc) · 1.49 KB
/
matrix1to2.py
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
import numpy as np
import matplotlib.pyplot as plt
import sqlite3
from tqdm import tqdm
from datetime import datetime
from random import choice
from glob import glob
import gmplot
from utils import get_route_details, get_stops_details, get_matrix1_map, get_matrix2_map
import os
from random import choice
stops_data = get_stops_details()
routes_data = get_route_details()
matrix1_map = get_matrix1_map(routes_data)
def m1to2(matrix1, route_id):
assert route_id in routes_data
stops = routes_data[route_id]
num_stops = len(stops)
matrix2 = np.zeros([int((num_stops*(num_stops-1))/2)+1, matrix1.shape[1]])
print(matrix2.shape)
for i in range(1, num_stops):
matrix2[get_matrix2_map(i-1, i, num_stops)] = matrix1[matrix1_map['map'][stops[i-1]][stops[i]]]
for j in range(i-2, -1, -1):
prev_time = matrix2[get_matrix2_map(j, i-1, num_stops)]
for k in range(matrix1.shape[1]):
if prev_time[k] == 0:
continue
ind = int(k + matrix1[i-1][k]//10)
assert ind < matrix1.shape[1]
matrix2[get_matrix2_map(j, i, num_stops), ind] = prev_time[k] + matrix1[matrix1_map['map'][stops[i-1]][stops[i]], ind]
return matrix2
matrix1 = np.load("./assets/processed/matrix/dbs-d-bus_movements_2020_08_05.db.npz")['matrix']
matrix2 = m1to2(matrix1, 534)
np.savez_compressed("./assets/processed/matrix2/dbs-d-bus_movements_2020_08_05.db.npz", matrix = matrix2)