-Ev3 Done -Main page done -Transit debugged -Uploaded transit sourceold
@ -0,0 +1,36 @@ | |||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" | |||||
android:viewportWidth="512" | |||||
android:viewportHeight="512" | |||||
android:width="512dp" | |||||
android:height="512dp"> | |||||
<path | |||||
android:pathData="M134.05 319.086l128.178 41.525c14.158 4.587 21.917 19.782 17.331 33.94l0 0c-4.587 14.158 -19.782 21.917 -33.94 17.331L117.44 370.357c-14.158 -4.587 -21.917 -19.782 -17.331 -33.94l0 0C104.696 322.258 119.891 314.499 134.05 319.086z" | |||||
android:fillColor="#A4C2F7" /> | |||||
<path | |||||
android:pathData="M35.93 179.649c-4.758 0.03 -9.421 1.335 -13.503 3.781c-1.386 -0.82 -2.842 -1.517 -4.35 -2.081c0.694 1.315 1.107 2.76 1.212 4.243c-3.504 2.738 -6.28 6.296 -8.081 10.362c-0.364 0.07 -0.732 0.12 -1.101 0.149c-0.379 -0.052 -0.754 -0.128 -1.123 -0.228v126.208c0.901 -0.333 1.847 -0.526 2.807 -0.572c1.078 0.011 2.146 0.203 3.161 0.566c1.503 1.91 3.256 3.609 5.211 5.053c0.324 0.742 0.567 1.517 0.722 2.311c0.526 -0.263 1.008 -0.594 1.514 -0.888c4.088 2.458 8.762 3.77 13.532 3.798c14.864 -0.044 26.904 -12.083 26.947 -26.947v-98.807C62.833 191.732 50.794 179.693 35.93 179.649z" | |||||
android:fillColor="#A4C2F7" /> | |||||
<path | |||||
android:pathData="M467.088 35.93L467.088 35.93c19.844 0 35.93 16.086 35.93 35.93V440.14c0 19.844 -16.086 35.93 -35.93 35.93l0 0c-19.844 0 -35.93 -16.086 -35.93 -35.93V71.86C431.158 52.016 447.244 35.93 467.088 35.93z" | |||||
android:fillColor="#7FACFA" /> | |||||
<path | |||||
android:pathData="M452.597 38.298c-0.498 4.606 -4.458 8.052 -9.088 7.91c-1.155 -0.024 -2.296 -0.256 -3.368 -0.684v421.504c0.207 -0.011 0.348 -0.114 0.561 -0.114c4.541 -0.15 8.456 3.169 9.052 7.673c15.487 -4.307 26.233 -18.372 26.317 -34.447V71.86C476.001 56.875 466.649 43.503 452.597 38.298z" | |||||
android:fillColor="#A4C2F7" /> | |||||
<path | |||||
android:pathData="M431.158 413.193L242.526 296.421 242.526 215.579 431.158 98.807Z" | |||||
android:fillColor="#A4C2F7" /> | |||||
<path | |||||
android:pathData="M404.211 404.211L62.877 296.421 62.877 215.579 404.211 107.789Z" | |||||
android:fillColor="#E3E7F2" /> | |||||
<path | |||||
android:pathData="M467.088 485.053c-24.792 -0.029 -44.883 -20.12 -44.912 -44.912V71.86c0 -24.804 20.108 -44.912 44.912 -44.912C491.892 26.947 512 47.055 512 71.86V440.14C511.971 464.933 491.88 485.024 467.088 485.053zM467.088 44.912c-14.876 0.016 -26.931 12.071 -26.947 26.947V440.14c0 14.883 12.065 26.947 26.947 26.947c14.883 0 26.947 -12.065 26.947 -26.947V71.86C494.019 56.984 481.964 44.929 467.088 44.912z" | |||||
android:fillColor="#428DFF" /> | |||||
<path | |||||
android:pathData="M431.158 422.175c-0.92 0 -1.834 -0.142 -2.711 -0.421L60.167 304.982c-3.733 -1.182 -6.271 -4.646 -6.272 -8.561v-80.842c0.001 -3.916 2.539 -7.38 6.272 -8.561L428.447 90.246c2.729 -0.864 5.707 -0.376 8.017 1.316c2.31 1.691 3.675 4.383 3.676 7.246v314.386C440.139 418.153 436.118 422.174 431.158 422.175L431.158 422.175zM71.86 289.842l350.316 111.079V111.079L71.86 222.158V289.842z" | |||||
android:fillColor="#428DFF" /> | |||||
<path | |||||
android:pathData="M253.903 422.184c-3.753 -0.002 -7.483 -0.594 -11.053 -1.754l-128.175 -41.526c-18.848 -6.15 -29.177 -26.381 -23.105 -45.254c6.146 -18.847 26.374 -29.177 45.246 -23.105l128.193 41.526c16.781 5.489 27.091 22.352 24.329 39.79C286.576 409.299 271.559 422.15 253.903 422.184zM125.772 326.763c-7.794 0.002 -14.702 5.019 -17.114 12.43c-3.003 9.433 2.15 19.525 11.553 22.623l128.184 41.526l0 0c9.436 3.046 19.557 -2.128 22.612 -11.562c3.055 -9.434 -2.111 -19.559 -11.542 -22.622l-128.184 -41.526C129.501 327.057 127.643 326.764 125.772 326.763L125.772 326.763z" | |||||
android:fillColor="#428DFF" /> | |||||
<path | |||||
android:pathData="M35.93 341.333c-19.835 -0.02 -35.91 -16.095 -35.93 -35.93v-98.807c0 -19.843 16.086 -35.93 35.93 -35.93s35.93 16.086 35.93 35.93v98.807C71.84 325.239 55.765 341.314 35.93 341.333zM35.93 188.632c-9.916 0.013 -17.952 8.049 -17.965 17.965v98.807c0 9.922 8.043 17.965 17.965 17.965s17.965 -8.043 17.965 -17.965v-98.807C53.882 196.68 45.846 188.644 35.93 188.632z" | |||||
android:fillColor="#428DFF" /> | |||||
</vector> |
@ -1,13 +1,58 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||||
xmlns:tools="http://schemas.android.com/tools" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="match_parent" | |||||
tools:context=".MainFragment"> | |||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="match_parent" | |||||
tools:context=".MainFragment" | |||||
android:orientation="vertical" | |||||
android:layout_marginTop="@dimen/fragment_margin"> | |||||
<LinearLayout | |||||
android:orientation="vertical" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="wrap_content" | |||||
android:layout_marginBottom="20dp" | |||||
android:layout_marginLeft="25dp"> | |||||
<TextView | |||||
android:text="Ankara,Çankaya" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="wrap_content" android:id="@+id/city_name" android:textSize="20sp" | |||||
android:layout_marginBottom="14dp" android:textColor="@android:color/black"/> | |||||
<LinearLayout | |||||
android:orientation="horizontal" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="wrap_content"> | |||||
<ImageView | |||||
android:layout_width="150dp" | |||||
android:layout_height="50dp" app:srcCompat="@mipmap/ic_launcher" android:id="@+id/forecast_img" | |||||
android:layout_weight="1"/> | |||||
<TextView | |||||
android:text="20 °C" | |||||
android:layout_width="200dp" | |||||
android:layout_height="wrap_content" android:id="@+id/temp_text" android:layout_weight="1" | |||||
android:textSize="35sp" android:textColor="#000000" android:layout_marginLeft="5dp"/> | |||||
<LinearLayout | |||||
android:orientation="vertical" | |||||
android:layout_width="310dp" | |||||
android:layout_height="match_parent" android:layout_weight="1" | |||||
android:layout_marginLeft="12dp"> | |||||
<TextView | |||||
android:text="TextView" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="wrap_content" android:id="@+id/humidity" android:textColor="#000000"/> | |||||
<TextView | |||||
android:text="TextView" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="wrap_content" android:id="@+id/pressure" android:textColor="#000000"/> | |||||
</LinearLayout> | |||||
</LinearLayout> | |||||
</LinearLayout> | |||||
<TextView | <TextView | ||||
android:text="Announcements:" | |||||
android:layout_width="match_parent" | android:layout_width="match_parent" | ||||
android:layout_height="match_parent" | |||||
android:text="@string/hello_blank_fragment"/> | |||||
</FrameLayout> | |||||
android:layout_height="wrap_content" android:id="@+id/announcement_title" android:textSize="24sp" | |||||
android:textColor="#000000" android:layout_marginBottom="15dp" android:layout_marginLeft="7dp"/> | |||||
<android.support.v7.widget.RecyclerView | |||||
android:layout_width="match_parent" | |||||
android:layout_height="match_parent" android:id="@+id/anouncements" android:layout_marginLeft="14dp"/> | |||||
</LinearLayout> |
@ -0,0 +1,9 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<module type="PYTHON_MODULE" version="4"> | |||||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |||||
<exclude-output /> | |||||
<content url="file://$MODULE_DIR$" /> | |||||
<orderEntry type="inheritedJdk" /> | |||||
<orderEntry type="sourceFolder" forTests="false" /> | |||||
</component> | |||||
</module> |
@ -0,0 +1,173 @@ | |||||
#!/usr/bin/env python3 | |||||
'''Hello to the world from ev3dev.org''' | |||||
import os | |||||
import sys | |||||
import time | |||||
import json | |||||
import datetime | |||||
import urllib3 | |||||
import requests | |||||
from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank | |||||
from ev3dev2.sensor import INPUT_1,INPUT_2 | |||||
from ev3dev2.sensor.lego import TouchSensor | |||||
from ev3dev2.sensor.lego import UltrasonicSensor | |||||
from ev3dev2.sound import Sound | |||||
from ev3dev2.button import Button | |||||
ON = True | |||||
OFF = False | |||||
def debug_print(*args, **kwargs): | |||||
print(*args, **kwargs, file=sys.stderr) | |||||
def reset_console(): | |||||
print('\x1Bc', end='') | |||||
def set_cursor(state): | |||||
if state: | |||||
print('\x1B[?25h', end='') | |||||
else: | |||||
print('\x1B[?25l', end='') | |||||
def set_font(name): | |||||
'''Sets the console font | |||||
A full list of fonts can be found with `ls /usr/share/consolefonts` | |||||
''' | |||||
os.system('setfont ' + name) | |||||
def raise_ramp(): | |||||
print("Raising ramp") | |||||
def get_closest_time(times, time): | |||||
closest = 0 | |||||
times = [datetime.datetime.strptime(i,"%H:%M") for i in times] | |||||
time = datetime.datetime.strptime(time,"%H:%M") | |||||
for i in times: | |||||
if i.hour < time.hour or (i.hour == time.hour and i.minute < time.minute): | |||||
continue | |||||
else: | |||||
if closest == 0: | |||||
closest = i | |||||
continue | |||||
if abs(i.hour - time.hour) < abs(closest.hour - time.hour): | |||||
closest = i | |||||
continue | |||||
elif abs(i.hour - time.hour) == abs(closest.hour - time.hour): | |||||
if i.minute - time.minute < closest.minute - time.minute: | |||||
closest = i | |||||
return closest.strftime("%H:%M") | |||||
def time_diff(t1, t2): | |||||
time1 = datetime.datetime.strptime(t1, "%H:%M") | |||||
time2 = datetime.datetime.strptime(t2, "%H:%M") | |||||
response = "" | |||||
if abs(time2.hour - time1.hour) < 10: | |||||
response += "0" | |||||
if time2.minute - time1.minute >= 0: | |||||
response += str(abs(time2.hour - time1.hour)) | |||||
else: | |||||
response += str(abs(time2.hour - time1.hour) - 1) | |||||
response += ":" | |||||
if abs(time2.minute - time1.minute) < 10: | |||||
response += "0" | |||||
response += str(abs(time2.minute - time1.minute)) | |||||
return response | |||||
def raise_ramp(motor1): | |||||
motor1.on_for_rotations(SpeedPercent(75), 5) | |||||
def main(): | |||||
start = time.time() | |||||
file = open("times.json","r") | |||||
time_data = json.loads(file.read()) | |||||
stop_data = [i for i in time_data.keys()] | |||||
debug_print(stop_data) | |||||
file.close() | |||||
time_start = "10:02" | |||||
debug_print('Started Code') | |||||
reset_console() | |||||
set_cursor(OFF) | |||||
set_font('Lat15-Terminus24x12') | |||||
alarms = [0,0,0] | |||||
stop = "11222" | |||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |||||
print('AKILLI DURAK') | |||||
sound = Sound() | |||||
us = UltrasonicSensor(INPUT_2) | |||||
us.MODE_US_DIST_CM | |||||
btn = Button() | |||||
m1 = LargeMotor(OUTPUT_A) | |||||
ts = TouchSensor(INPUT_1) | |||||
while 1: | |||||
if us.distance_centimeters < 15: | |||||
sound.speak("Please select a stop") | |||||
i = 0 | |||||
reset_console() | |||||
print(stop_data[i%len(stop_data)]) | |||||
while not btn.enter: | |||||
if btn.up: | |||||
i += 1 | |||||
reset_console() | |||||
print(stop_data[i%len(stop_data)]) | |||||
time.sleep(0.1) | |||||
if btn.down: | |||||
i -= 1 | |||||
reset_console() | |||||
print(stop_data[i%len(stop_data)]) | |||||
time.sleep(0.1) | |||||
closest = datetime.datetime.strptime(time_diff(time_start,get_closest_time(time_data[stop_data[i%len(stop_data)]]["weekday"][:],time_start)),"%H:%M") | |||||
difference = datetime.timedelta(hours=closest.hour,minutes=closest.minute).total_seconds()+start | |||||
if not difference in alarms: | |||||
alarms[i%len(stop_data)] = difference | |||||
r = requests.get("https://192.168.44.50:5000/bus?line={}&stop={}".format(stop_data[i%len(stop_data)],stop), verify=False) | |||||
print(difference-time.time()) | |||||
time.sleep(1) | |||||
reset_console() | |||||
print("AKILLI DURAK") | |||||
for i in range(len(alarms)): | |||||
if alarms[i] == 0: | |||||
continue | |||||
else: | |||||
if alarms[i]-time.time()<0: | |||||
reset_console() | |||||
print("Bus no {} has arrived".format(stop_data[i%len(stop_data)])) | |||||
sound.speak("Bus no {} has arrived".format(stop_data[i%len(stop_data)])) | |||||
sound.speak("Would you like a ramp?") | |||||
waiter = time.time() | |||||
pressed = True | |||||
while time.time()-waiter < 10 and pressed: | |||||
if ts.is_pressed: | |||||
pressed = False | |||||
raise_ramp(m1) | |||||
reset_console() | |||||
print("AKILLI DURAK") | |||||
alarms[i] = 0 | |||||
if __name__ == '__main__': | |||||
main() |
@ -0,0 +1,4 @@ | |||||
Traceback (most recent call last): | |||||
File "/home/robot/bus_stop/main.py", line 9, in <module> | |||||
import urllib3 | |||||
ImportError: No module named 'urllib3' |
@ -0,0 +1,338 @@ | |||||
{ | |||||
"188-5": { | |||||
"saturday": [], | |||||
"weekday": [ | |||||
"06:20", | |||||
"06:35", | |||||
"06:35", | |||||
"06:50", | |||||
"06:50", | |||||
"07:05", | |||||
"07:17", | |||||
"07:20", | |||||
"07:29", | |||||
"07:35", | |||||
"07:41", | |||||
"07:50", | |||||
"07:53", | |||||
"08:05", | |||||
"08:05", | |||||
"08:20", | |||||
"08:20", | |||||
"08:35", | |||||
"08:35", | |||||
"08:50", | |||||
"08:50", | |||||
"09:05", | |||||
"09:05", | |||||
"09:25", | |||||
"09:25", | |||||
"09:45", | |||||
"09:45", | |||||
"10:05", | |||||
"10:05", | |||||
"10:25", | |||||
"10:25", | |||||
"10:45", | |||||
"10:45", | |||||
"11:05", | |||||
"11:05", | |||||
"11:25", | |||||
"11:25", | |||||
"11:45", | |||||
"11:45", | |||||
"12:05", | |||||
"12:05", | |||||
"12:25", | |||||
"12:25", | |||||
"12:45", | |||||
"12:45", | |||||
"13:05", | |||||
"13:05", | |||||
"13:25", | |||||
"13:25", | |||||
"13:45", | |||||
"13:45", | |||||
"14:05", | |||||
"14:05", | |||||
"14:25", | |||||
"14:25", | |||||
"14:45", | |||||
"14:45", | |||||
"15:05", | |||||
"15:05", | |||||
"15:25", | |||||
"15:25", | |||||
"15:45", | |||||
"15:45", | |||||
"16:05", | |||||
"16:05", | |||||
"16:25", | |||||
"16:25", | |||||
"16:45", | |||||
"16:45", | |||||
"17:05", | |||||
"17:05", | |||||
"17:25", | |||||
"17:25", | |||||
"17:45", | |||||
"17:45", | |||||
"18:05", | |||||
"18:05", | |||||
"18:25", | |||||
"18:25", | |||||
"18:45", | |||||
"18:45", | |||||
"19:05", | |||||
"19:05", | |||||
"19:35", | |||||
"19:35", | |||||
"20:05", | |||||
"20:05", | |||||
"20:35", | |||||
"20:35", | |||||
"21:05", | |||||
"21:05", | |||||
"21:35", | |||||
"21:35", | |||||
"22:05", | |||||
"22:05" | |||||
] | |||||
}, | |||||
"173-1": { | |||||
"saturday": [ | |||||
"06:49", | |||||
"07:19", | |||||
"07:49", | |||||
"08:20", | |||||
"08:50", | |||||
"09:19", | |||||
"10:19", | |||||
"11:20", | |||||
"12:19", | |||||
"13:18", | |||||
"14:18", | |||||
"15:19", | |||||
"15:49", | |||||
"16:19", | |||||
"16:49", | |||||
"17:19", | |||||
"17:49", | |||||
"18:24", | |||||
"19:03", | |||||
"20:03", | |||||
"21:05", | |||||
"22:05" | |||||
], | |||||
"weekday": [ | |||||
"06:29", | |||||
"06:49", | |||||
"07:09", | |||||
"07:29", | |||||
"07:49", | |||||
"08:10", | |||||
"08:35", | |||||
"09:14", | |||||
"09:54", | |||||
"10:34", | |||||
"11:15", | |||||
"11:55", | |||||
"12:35", | |||||
"13:14", | |||||
"13:54", | |||||
"14:34", | |||||
"14:54", | |||||
"15:14", | |||||
"15:34", | |||||
"15:54", | |||||
"16:14", | |||||
"16:34", | |||||
"16:54", | |||||
"17:15", | |||||
"17:35", | |||||
"17:55", | |||||
"18:15", | |||||
"18:35", | |||||
"19:03", | |||||
"19:33", | |||||
"20:03", | |||||
"21:05", | |||||
"22:05" | |||||
] | |||||
}, | |||||
"185-3": { | |||||
"saturday": [ | |||||
"05:55", | |||||
"06:04", | |||||
"06:13", | |||||
"06:22", | |||||
"06:31", | |||||
"06:39", | |||||
"06:47", | |||||
"06:55", | |||||
"06:56", | |||||
"07:03", | |||||
"07:05", | |||||
"07:11", | |||||
"07:14", | |||||
"07:19", | |||||
"07:23", | |||||
"07:27", | |||||
"07:33", | |||||
"07:36", | |||||
"07:43", | |||||
"07:53", | |||||
"08:03", | |||||
"08:13", | |||||
"08:23", | |||||
"08:33", | |||||
"08:43", | |||||
"08:53", | |||||
"09:02", | |||||
"09:11", | |||||
"09:20", | |||||
"09:29", | |||||
"09:38", | |||||
"09:47", | |||||
"09:56", | |||||
"10:05", | |||||
"10:14", | |||||
"10:23", | |||||
"10:32", | |||||
"10:41", | |||||
"10:50", | |||||
"10:59", | |||||
"11:08", | |||||
"11:17", | |||||
"11:26", | |||||
"11:35", | |||||
"11:45", | |||||
"11:55", | |||||
"12:05", | |||||
"12:15", | |||||
"12:25", | |||||
"12:35", | |||||
"12:45", | |||||
"12:55", | |||||
"13:05", | |||||
"13:15", | |||||
"13:25", | |||||
"13:35", | |||||
"13:45", | |||||
"13:55", | |||||
"14:05", | |||||
"14:15", | |||||
"14:25", | |||||
"14:35", | |||||
"14:45", | |||||
"14:55", | |||||
"15:05", | |||||
"15:15", | |||||
"15:25", | |||||
"15:35", | |||||
"15:45", | |||||
"15:55", | |||||
"16:05", | |||||
"16:15", | |||||
"16:25", | |||||
"16:35", | |||||
"16:45", | |||||
"16:55", | |||||
"17:05", | |||||
"17:15", | |||||
"17:25", | |||||
"17:35", | |||||
"17:45", | |||||
"17:55", | |||||
"18:05", | |||||
"18:15", | |||||
"18:25", | |||||
"18:35", | |||||
"18:45", | |||||
"18:55", | |||||
"19:05", | |||||
"19:15", | |||||
"19:25", | |||||
"19:35", | |||||
"19:45", | |||||
"19:55", | |||||
"20:01", | |||||
"20:06", | |||||
"20:11", | |||||
"20:17", | |||||
"20:21", | |||||
"20:28", | |||||
"20:31", | |||||
"20:39", | |||||
"20:46", | |||||
"20:51", | |||||
"21:03", | |||||
"21:15", | |||||
"21:16", | |||||
"21:29", | |||||
"21:44", | |||||
"22:03", | |||||
"22:26" | |||||
], | |||||
"weekday": [ | |||||
"05:51", | |||||
"06:00", | |||||
"06:09", | |||||
"06:18", | |||||
"06:27", | |||||
"06:36", | |||||
"06:44", | |||||
"06:50", | |||||
"06:52", | |||||
"06:59", | |||||
"07:00", | |||||
"07:07", | |||||
"07:08", | |||||
"07:14", | |||||
"07:17", | |||||
"07:21", | |||||
"07:26", | |||||
"07:28", | |||||
"07:36", | |||||
"07:46", | |||||
"07:56", | |||||
"08:06", | |||||
"08:16", | |||||
"08:26", | |||||
"08:36", | |||||
"08:46", | |||||
"08:55", | |||||
"09:05", | |||||
"09:15", | |||||
"09:25", | |||||
"09:35", | |||||
"09:44", | |||||
"09:53", | |||||
"10:03", | |||||
"10:12", | |||||
"10:21", | |||||
"10:30", | |||||
"10:39", | |||||
"10:48", | |||||
"10:57", | |||||
"11:06", | |||||
"11:15", | |||||
"11:24", | |||||
"11:34", | |||||
"11:43", | |||||
"11:52", | |||||
"12:01", | |||||
"12:10", | |||||
"12:19", | |||||
"12:28", | |||||
"12:37", | |||||
"12:46", | |||||
"12:55", | |||||
"13:05", | |||||
"13:15", | |||||
"13:25", | |||||
"13:35", | |||||
"13:45", | |||||
"13:55", | |||||
"14:05" | |||||
]}} |
@ -0,0 +1,196 @@ | |||||
import xml.etree.ElementTree as ET | |||||
import cv2 | |||||
import numpy as np | |||||
import os | |||||
import json | |||||
from pysolar.solar import * | |||||
from datetime import datetime | |||||
def timeAverage(): | |||||
data_file = open("data.json","r") | |||||
time_file = open("timely.json","w") | |||||
averages = json.loads(data_file.read()) | |||||
timely = {} | |||||
altitudes = {} | |||||
for key in averages: | |||||
date = key[37:-13] | |||||
time = key[49:-4].replace("_",":") | |||||
averages[key]["time"]=time | |||||
averages[key]["date"]=date | |||||
data_file.close() | |||||
data_file = open("data.json","w") | |||||
data_file.write(json.dumps(averages)) | |||||
for key in averages: | |||||
time = datetime.strptime(averages[key]["date"] + " " + averages[key]["time"] + " -0300","%Y-%m-%d %H:%M:%S %z") | |||||
altitude = int(get_altitude(-25.4269081,-49.3318036,time)) | |||||
altitudes[averages[key]["date"] + " " + averages[key]["time"] ] = altitude | |||||
if not (altitude in timely): | |||||
timely[altitude] = {} | |||||
for spot in averages[key]: | |||||
if(spot == "time" or spot == "date"): | |||||
continue | |||||
if not spot in timely[altitude]: | |||||
timely[altitude][spot]=[] | |||||
timely[altitude][spot].append({"r":averages[key][spot]["r"],"b":averages[key][spot]["b"],"g":averages[key][spot]["g"]}) | |||||
print(altitudes) | |||||
for key in timely: | |||||
for id in timely[key]: | |||||
total = {"r":0,"g":0,"b":0} | |||||
for i in range(len(timely[key][id])): | |||||
for color in total: | |||||
total[color] += timely[key][id][i][color] | |||||
for color in total: | |||||
total[color] = total[color] / len(timely[key][id]) | |||||
timely[key][id] = total | |||||
print(timely) | |||||
timely_json = json.dumps(timely) | |||||
time_file.write(timely_json) | |||||
data_file.close() | |||||
time_file.close() | |||||
def generateData(locations,image,show,averages): | |||||
loc_images = {} | |||||
average_values = {} | |||||
average_total=[0,0,0] | |||||
for col in range(len(image)): | |||||
for pix in range(len(image[col])): | |||||
if (image[col][pix] == [255,255,255]).all(): | |||||
image[col][pix] == [255,255,254] | |||||
for i in locations: | |||||
temp = locations[i] | |||||
pts = np.array([[int(temp[0]['x']),int(temp[0]['y'])], | |||||
[int(temp[1]['x']),int(temp[1]['y'])], | |||||
[int(temp[2]['x']),int(temp[2]['y'])], | |||||
[int(temp[3]['x']),int(temp[3]['y'])]]) | |||||
rect = cv2.boundingRect(pts) | |||||
x,y,w,h = rect | |||||
croped = image[y:y+h, x:x+w].copy() | |||||
pts = pts - pts.min(axis=0) | |||||
mask = np.zeros(croped.shape[:2], np.uint8) | |||||
cv2.drawContours(mask, [pts], -1, (255, 255, 255), -1, cv2.LINE_AA) | |||||
dst = cv2.bitwise_and(croped, croped, mask=mask) | |||||
bg = np.ones_like(croped, np.uint8)*255 | |||||
cv2.bitwise_not(bg,bg, mask=mask) | |||||
dst2 = bg+ dst | |||||
split_len = len(dst2)//3 | |||||
splitted = [dst2[:split_len,:],dst2[split_len:split_len*2,:],dst2[split_len*2:,:]] | |||||
loc_images[i]=[dst2] | |||||
for lot in loc_images: | |||||
average_values[lot] = [] | |||||
for i in range(1): | |||||
diff_pix = 0 | |||||
reps = 0 | |||||
avg_rgb = [0,0,0] | |||||
rgb = ["b","g","r"] | |||||
for col in loc_images[lot][i]: | |||||
for pix in col: | |||||
if (pix == [255,255,255]).all(): | |||||
continue | |||||
different = False | |||||
print("[",end="") | |||||
for j in range(3): | |||||
print(abs(int(averages[lot][rgb[i]]-pix[i])) , end=",") | |||||
if abs(averages[lot][rgb[i]]-pix[i]) > 59: | |||||
different = True | |||||
reps += 1 | |||||
diff_pix += different | |||||
print("]",end=" ") | |||||
print("") | |||||
print("\n\n") | |||||
average_values[lot] = (diff_pix/reps)*100 | |||||
if lot in show: | |||||
cv2.imshow("a" , loc_images[lot][0]) | |||||
cv2.waitKey(0) | |||||
return average_values | |||||
def findSpot(img_loc,locations): | |||||
empty = [] | |||||
timely_values = time_file = open("timely.json","r") | |||||
timely_averages = json.loads(timely_values.read()) | |||||
img = cv2.imread(img_loc) | |||||
date = img_loc[37:-13] | |||||
time = img_loc[49:-4] | |||||
time = time.replace("_",":") | |||||
time = datetime.strptime(date + " " + time + " -0300","%Y-%m-%d %H:%M:%S %z") | |||||
altitude = int(get_altitude(-25.4269081,-49.3318036,time)) | |||||
base_value = timely_averages[str(altitude)] | |||||
print(altitude) | |||||
averages = generateData(locations,img,[],base_value) | |||||
for i in averages: | |||||
print(i + " " + str(averages[i])) | |||||
for i in locations: | |||||
if(averages[i] > 32): | |||||
color=[0,0,255] | |||||
empty.append(i) | |||||
else: | |||||
color=[0,255,0] | |||||
corners = [[],[]] | |||||
for j in range(0,4): | |||||
val2 = j+1 | |||||
if(val2 == 4): | |||||
val2 = 0 | |||||
pt1 = (int(locations[i][j]["x"]),int(locations[i][j]["y"])) | |||||
pt2 = (int(locations[i][val2]["x"]),int(locations[i][val2]["y"])) | |||||
cv2.line(img,pt1,pt2,color) | |||||
corners[0].append(int(locations[i][j]["x"])) | |||||
corners[1].append(int(locations[i][j]["y"])) | |||||
x1=min(corners[0][0],corners[0][1],corners[0][2],corners[0][3]); | |||||
x2=max(corners[0][0],corners[0][1],corners[0][2],corners[0][3]); | |||||
y1=min(corners[1][0],corners[1][1],corners[1][2],corners[1][3]); | |||||
y2=max(corners[1][0],corners[1][1],corners[1][2],corners[1][3]); | |||||
pt = (int((x1+x2)/2),int((y1+y2)/2)) | |||||
cv2.putText(img,str(i), pt, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 255) | |||||
cv2.imshow("Parking Lot",img) | |||||
cv2.waitKey(0) | |||||
return empty | |||||
location_file = open("locations.json","r") | |||||
location_json = json.loads(location_file.read()) | |||||
empty_locs = findSpot('./PKLot/PKLot/PUCPR/Sunny/2012-09-11/2012-09-11_18_08_41.jpg',location_json) | |||||
closest = 1000 | |||||
for i in empty_locs: | |||||
print (location_json[i][4]) | |||||
if location_json[i][4] < closest: | |||||
closest = int(i) | |||||
print("The closest spot is " + str(closest)) | |||||
print("done") | |||||
@ -0,0 +1,17 @@ | |||||
from flask import Flask, request | |||||
from flask_restful import Resource, Api | |||||
import json | |||||
app = Flask(__name__) | |||||
api = Api(app) | |||||
buses = {} | |||||
with open("modules/databases/announcements.json","r") as f: | |||||
announcements = json.loads(f.read()) | |||||
class Announcement(Resource): | |||||
def get(self): | |||||
return announcements |
@ -0,0 +1,17 @@ | |||||
from flask import Flask, request | |||||
from flask_restful import Resource, Api, abort | |||||
app = Flask(__name__) | |||||
api = Api(app) | |||||
buses = {} | |||||
class Bus(Resource): | |||||
def get(self): | |||||
args = request.args | |||||
if not args["line"] in buses: | |||||
buses[args["line"]] = [] | |||||
if not args["stop"] in buses[args["line"]]: | |||||
buses[args["line"]].append(args["stop"]) | |||||
return "OK" |
@ -0,0 +1,10 @@ | |||||
[ | |||||
{ | |||||
"text1": "Yeni park", | |||||
"text2": "Çankaya 100.Yıl mahallesinde yeni park" | |||||
}, | |||||
{ | |||||
"text1": "Muhtarlık Seçimleri", | |||||
"text2": "Muhtarlı seçimleri 11.05.2019 tarihinde yapılacak" | |||||
} | |||||
] |
@ -0,0 +1,119 @@ | |||||
import cv2 | |||||
import numpy as np | |||||
import json | |||||
from matplotlib import pyplot as plt | |||||
import cv2 | |||||
import numpy as np | |||||
import json | |||||
import os | |||||
from matplotlib import pyplot as plt | |||||
import xml.etree.ElementTree as ET | |||||
import cv2 | |||||
import numpy as np | |||||
import os | |||||
import json | |||||
from pysolar.solar import * | |||||
from datetime import datetime | |||||
def calcAvg(img,locations_xml): | |||||
locations_extracted = [] | |||||
loc_images = {} | |||||
average_values = {} | |||||
for i in range( len( locations_xml ) ): | |||||
try: | |||||
locations_extracted.append([]) | |||||
for j in range(4): | |||||
locations_extracted[i].append(locations_xml[i][1][j].attrib) | |||||
locations_extracted[i].append(locations_xml[i].attrib['occupied']) | |||||
locations_extracted[i].append(locations_xml[i].attrib['id']) | |||||
except Exception: | |||||
print("xml corrupt!") | |||||
return {} | |||||
for col in range(len(img)): | |||||
for pix in range(len(img[col])): | |||||
if (img[col][pix] == [255,255,255]).all(): | |||||
img[col][pix] == [255,255,254] | |||||
for i in range(len(locations_extracted)): | |||||
temp = locations_extracted[i] | |||||
pts = np.array([[int(temp[0]['x']),int(temp[0]['y'])], | |||||
[int(temp[1]['x']),int(temp[1]['y'])], | |||||
[int(temp[2]['x']),int(temp[2]['y'])], | |||||
[int(temp[3]['x']),int(temp[3]['y'])]]) | |||||
rect = cv2.boundingRect(pts) | |||||
x,y,w,h = rect | |||||
croped = img[y:y+h, x:x+w].copy() | |||||
pts = pts - pts.min(axis=0) | |||||
mask = np.zeros(croped.shape[:2], np.uint8) | |||||
cv2.drawContours(mask, [pts], -1, (255, 255, 255), -1, cv2.LINE_AA) | |||||
dst = cv2.bitwise_and(croped, croped, mask=mask) | |||||
bg = np.ones_like(croped, np.uint8)*255 | |||||
cv2.bitwise_not(bg,bg, mask=mask) | |||||
dst2 = bg+ dst | |||||
blurred = cv2.GaussianBlur(dst2,(5,5),3) | |||||
edges = cv2.Canny(blurred,100,100) | |||||
if not temp[4] in loc_images: | |||||
loc_images[temp[4]] = {} | |||||
loc_images[temp[4]][temp[5]] = edges | |||||
for state in loc_images: | |||||
average_values[state] = {} | |||||
for lot in loc_images[state]: | |||||
reps = 0 | |||||
for col in loc_images[state][lot]: | |||||
for pix in col: | |||||
if(pix == 255): | |||||
reps += 1 | |||||
average_values[state][lot] = reps | |||||
print (average_values) | |||||
return average_values | |||||
def generateAvg(): | |||||
dates = os.listdir('./PKLot/PKLot/PUCPR/Sunny') | |||||
imgs = [] | |||||
averages={} | |||||
back_file = open("backup.json","w") | |||||
back_file.write("{") | |||||
for i in range(len(dates)): | |||||
imgs.append(os.listdir(os.path.join('./PKLot/PKLot/PUCPR/Sunny',dates[i]))) | |||||
for i in range(len(imgs)): | |||||
for j in range(len(imgs[i])): | |||||
if(imgs[i][j][-4:] == ".jpg"): | |||||
try: | |||||
img_location = os.path.join('./PKLot/PKLot/PUCPR/Sunny',dates[i],imgs[i][j]) | |||||
locs = ET.parse(img_location[:-4] + ".xml").getroot() | |||||
print(img_location,end=" ") | |||||
average = calcAvg(cv2.imread(img_location),locs) | |||||
if not(average == {}): | |||||
averages[img_location] = average | |||||
back_file.write("'"+img_location + "':" + str(average)) | |||||
except Exception: | |||||
continue | |||||
back_file.write("}") | |||||
js = json.dumps(averages) | |||||
print(js) | |||||
fp = open('data.json', 'w') | |||||
fp.write(js) | |||||
fp.close() | |||||
generateAvg() | |||||
@ -0,0 +1,28 @@ | |||||
import os | |||||
import copy | |||||
import json | |||||
from flask import Flask, request | |||||
from flask_restful import Resource, Api, abort | |||||
app = Flask(__name__) | |||||
api = Api(app) | |||||
class Empty(Resource): | |||||
def get(self): | |||||
try: | |||||
rating = copy.deepcopy(ratings[rating_id - 1]) | |||||
del rating['rates'] | |||||
return rating | |||||
except: | |||||
abort(404, error="Rating {} doesn't exist".format(rating_id)) | |||||