This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HOSTNAME=0.0.0.0 | |
PORT=8000 | |
GMAP_API_KEY="..." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dotenv = require('dotenv'); | |
const express = require('express'); | |
// Loads environment variables | |
dotenv.config(); | |
const hostname = process.env.HOSTNAME; | |
const port = process.env.PORT; | |
const gmap_api_key = process.env.GMAP_API_KEY; | |
// Setups the server. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INPUT = "merged_traffic_data.csv" | |
OUTPUT = "merged_traffic_data_for_fusion.csv" | |
with open(INPUT) as fin: | |
with open(OUTPUT, 'w') as fout: | |
is_first_line = True | |
for line in fin: | |
if is_first_line: | |
fout.write(',location,death,injury,time\n') | |
is_first_line = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lat | lng | death | injury | time | ||
---|---|---|---|---|---|---|
0 | 23.962235 | 120.578892 | 1 | 0 | 107年01月01日 05時12分00秒 | |
1 | 25.036777 | 121.24492 | 1 | 0 | 107年01月01日 14時55分00秒 | |
2 | 24.682004 | 120.86117800000001 | 1 | 3 | 107年01月01日 17時10分13秒 | |
3 | 23.82721 | 120.771165 | 1 | 0 | 107年01月01日 17時30分20秒 | |
4 | 24.102967 | 120.502953 | 1 | 0 | 107年01月01日 19時30分00秒 | |
5 | 23.700923 | 120.45893000000001 | 1 | 0 | 107年01月02日 09時51分00秒 | |
6 | 24.959526999999998 | 121.219521 | 1 | 1 | 107年01月02日 10時00分00秒 | |
7 | 24.923638 | 121.371249 | 1 | 0 | 107年01月02日 13時34分00秒 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_columns(data_source): | |
dataframe = data_source.dataframe | |
dataframe['death'] = dataframe['死亡受傷人數'].map( | |
lambda x: x.split(';')[0][2:] if isinstance(x, str) else 0) | |
dataframe['injury'] = dataframe['死亡受傷人數'].map( | |
lambda x: x.split(';')[1][2:] if isinstance(x, str) else 0) | |
dataframe.rename(columns={u'發生時間':'time'}, inplace=True) | |
dataframe.rename(columns={u'經度':'lng'}, inplace=True) | |
dataframe.rename(columns={u'緯度':'lat'}, inplace=True) | |
dataframe = dataframe[pd.notnull(dataframe['lng'])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CachableDataSource: | |
def __init__(self, url): | |
self.url = url | |
self.cache_filepath = self.__get_cache_filepath(url) | |
if os.path.isfile(self.cache_filepath): | |
self.__load_cache() | |
else: | |
self.__load_dataframe() | |
self.__save_cache() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
# Downloads CSV files by giving the URLs, and store the downloaded raw | |
# data in a object called CachableDataSource | |
data_sources = [CachableDataSource(url) for url in TRAFFIC_ACCIDENT_DATA] | |
# Extracts the columns we want from the downloaded data sources. | |
dataframes = [extract_columns(ds) for ds in data_sources] | |
# Merges all the dataframes into one big dataframe. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TRAFFIC_ACCIDENT_DATA = [ | |
"https://www.npa.gov.tw/NPAGip/wSite/public/Data/f1551682182614.csv", | |
"https://www.npa.gov.tw/NPAGip/wSite/public/Data/f1551682149786.csv" | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df_l = pd.read_csv('20180220.csv', | |
names=['TimeInterval', 'GantryFrom', 'GantryTo', | |
'VehicleType', 'SpaceMeanSpeed', '交通量']) | |
df_2l = pd.read_csv('20180219.csv', | |
names=['TimeInterval', 'GantryFrom', 'GantryTo', | |
'VehicleType', 'SpaceMeanSpeed', '交通量']) | |
def print_summary(df, field): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""This script loads a pretrained InceptionV3 model, then retrains the | |
fully-connected layer using a given training data. Per epoch, one model with | |
weight values and one prediction on a given test data are saved to disk. | |
Input: | |
- X_TRAIN_FILENAME: the location of training dataset file (.npy file) | |
- Y_TRAIN_FILENAME: the location of training label file (.npy file) | |
- X_TEST_FILENAME: the location of the dataset to predict (.npy file) | |
- N_CLASSES: number of classes to classify |