Last active
July 22, 2017 20:48
-
-
Save dohvis/a81b0798c377d92585b67cacb039f6c2 to your computer and use it in GitHub Desktop.
8100번 승하차 기록
This file contains 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
from pymongo import MongoClient | |
from datetime import datetime as d, timedelta | |
client = MongoClient('mongodb://user:passwd@localhost:33066/DATABASE') | |
db = client.busDB | |
bojung = '228001003' | |
ori = '206000040' | |
migum = '206000087' | |
jungja_station = "206000725" | |
bundang = '206000082' | |
for day in (10, 11, 12, 13, 14): | |
start = d(2017, 7, day, 8, 30) | |
end = d(2017, 7, day, 9, 30) | |
pre_buses = db.b8100.find({ | |
"crawled_at": {"$gte":start, "$lt":end}, "fromStationId": migum, "toStationId": jungja_station | |
}) | |
post_buses = db.b8100.find({ | |
"crawled_at": {"$gte":start, "$lt":end}, "fromStationId": jungja_station, "toStationId": bundang | |
}) | |
bus_no = '' | |
bus_cnt = 0 | |
remainseat_sum = 0 | |
avg_period = timedelta() | |
avg_increase = 0 | |
crawled_at =None | |
print('-'*10, '7월', day, '일', '-'*10) | |
for bus1, bus2 in zip(pre_buses, post_buses): | |
if bus_no == bus1['busNo'][0]: | |
continue | |
bus_cnt += 1 | |
bus_no = bus1['busNo'][0] | |
remain_seat = bus1["busSapceList"][0]['remainSeatCnt1'] | |
remainseat_sum += int(remain_seat) | |
if crawled_at: | |
period = bus1['crawled_at'] - crawled_at | |
avg_period += period | |
crawled_at = bus1['crawled_at'] | |
print(bus_no, remain_seat, crawled_at, end=' | ') | |
increase = int(remain_seat) - int(bus2["busSapceList"][0]['remainSeatCnt1']) | |
avg_increase += increase | |
print("{}명 탑승".format(increase)) | |
avg_increase = avg_increase/bus_cnt | |
avg_period /= bus_cnt | |
remainseat_avg = remainseat_sum / bus_cnt | |
print("{}일: 버스는 평균 {:2}분 간격으로 오고 평균 {}명이 탑승함. 남은 자리 평균: {}석".format(day, round(avg_period.total_seconds()/60, 2), avg_increase, remainseat_avg )) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment