Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
edd6108
configure chatroom settings
mell00 Jan 14, 2023
1816dc3
Create .env
mell00 Jan 14, 2023
fa87350
keys
mell00 Jan 14, 2023
d89eee1
Create database functions
mell00 Jan 14, 2023
21012e9
Merge remote-tracking branch 'origin/branch'
mell00 Jan 14, 2023
25eb34c
move some docs to make way for new app
mell00 Jan 14, 2023
6bb4552
new chat app
mell00 Jan 14, 2023
432e19e
new chat app (fix file names later)
mell00 Jan 14, 2023
febcdba
Merge branch 'master' of https://github.com/mell00/sustainableCarpool
mell00 Jan 14, 2023
33f7c81
chat app backend
mell00 Jan 15, 2023
4d9c477
updated database functions
mell00 Jan 15, 2023
d7f3a0f
work done on database
mell00 Jan 15, 2023
34699c4
Delete .env
mell00 Jan 15, 2023
3f3820c
database
mell00 Jan 15, 2023
4cbc622
Merge branch 'master' of https://github.com/mell00/sustainableCarpool
mell00 Jan 15, 2023
82a15ae
RecommendationAlgorithm.py
Hadi-M-Ibrahim Jan 15, 2023
4266584
Merge pull request #1 from Hadi-M-Ibrahim/patch-1
mell00 Jan 15, 2023
1dc017f
reorganization
mell00 Jan 15, 2023
dd4c854
added missing form
mell00 Jan 15, 2023
b2d92e1
add column write function
mell00 Jan 15, 2023
339d047
updated algo
Hadi-M-Ibrahim Jan 15, 2023
e90907a
fixed indent
Hadi-M-Ibrahim Jan 15, 2023
8557138
Published Api key by mistake
Hadi-M-Ibrahim Jan 15, 2023
28a4ede
Simplify Database
Hadi-M-Ibrahim Jan 15, 2023
226a1c7
Update database_functions.py
Hadi-M-Ibrahim Jan 15, 2023
884e647
Update database.csv
Hadi-M-Ibrahim Jan 15, 2023
ae1dbed
Update database.csv
Hadi-M-Ibrahim Jan 15, 2023
9fe5921
Update database.csv
Hadi-M-Ibrahim Jan 15, 2023
42798d8
Update RecommendationAlgorithm.py
Hadi-M-Ibrahim Jan 15, 2023
3fec966
Quickly added comments
Hadi-M-Ibrahim Jan 15, 2023
7d7dd67
Delete profile_pics directory
Hadi-M-Ibrahim Jan 15, 2023
7f54ddc
Merge pull request #2 from mell00/Hadi-M-Ibrahim-patch-1
mell00 Jan 15, 2023
4bb45db
Merge pull request #3 from mell00/Hadi-M-Ibrahim-patch-4
mell00 Jan 15, 2023
561fc24
Merge branch 'master' into Hadi-M-Ibrahim-patch-2
mell00 Jan 15, 2023
02673bb
Merge pull request #5 from mell00/Hadi-M-Ibrahim-patch-2
mell00 Jan 15, 2023
b2553cb
Merge branch 'master' into Hadi-M-Ibrahim-patch-3
mell00 Jan 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions WBBackend/database/database.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Name, Age, starting_location, Carbon_Offset
Cheddar,23,Castle Park,483
McCheese,18,California Citrus State Historic Park,801
GoodBoy,34,UC Riverside Botanic Gardens,11
Jackson,48,Andulka Park,420
GreenBean,39,Riverside Art Museum,69
Mochi,21,Doty Trust Park,41
35 changes: 35 additions & 0 deletions WBBackend/database/database_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pandas as pd
import ./components/form.js

tripdetails = ["Name", "Age", "starting_location", "Carbon_Offset", ]

# write new trip data into table
def write_new():
df = pd.read_csv('csvfilepath')

# how to store info fromtheform into somearray

# second dataframe for new row
df_new = pd.DataFrame(data=somearray, columns=tripdetails)

# add new row to original data
df.append(df_new)

# update csv file
trips_df.to_csv

return

# read row at index
def read(index):
df = pd.read_csv('csvfilepath')

# store in multiple variables?
# photofile = df.loc[index, 'Photofile']
# ...

# store in one dataframe
df_read = pd.DataFrame(data=df.loc([index], columns=tripdetails)

def write(index):
return df.to_csv("test.txt", columns=[index], header=False, index=False)
30 changes: 30 additions & 0 deletions WBBackend/database/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
window.addEventListener( "load", function () {
function sendData(data) {
const XHR = new XMLHttpRequest();

const FD = new FormData(form);

for(i in data) {
FD.append(i,data[name]);
}

XHR.addEventListener( "load", function(event) {
alert( event.target.responseText );
} );

XHR.addEventListener( "error", function( event ) {
alert( 'Oops! Something went wrong.' );
} );

XHR.open( "POST", "./database_functions.py" );

XHR.send(FD);
}
let form = document.getElementById( "form" );

form.addEventListener( "submit", function ( event ) {
event.preventDefault();

sendData();
} );
} );
Empty file added WBBackend/database/list.txt
Empty file.
68 changes: 68 additions & 0 deletions WBBackend/twilio_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from twilio.rest import Client
from twilio.twiml.messaging_response import MessagingResponse
import os

TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
TWILIO_PHONE_NUMBER = '+12166665403'
client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) #twilio account client

import datetime as dt
CAVEMANAGER = ("Desolation Wilderness", "Ranger Maria", 7038877463) #to be hard coded into device
##############################################
##############################################
# UPDATE: to be imported somehow from database
##############################################
##############################################
check_in = {"photo": "123.jpg", "date_time": dt.datetime(2020,3,7,10,0),
"user": (123456, "Sonia Meyer", 7038877463), "group_size": 3,
"expected_out": dt.datetime(2020,3,7,18,0), "call_out": dt.datetime(2020,3,8,8,0)}
check_out = {"photo": "456.jpg", "date_time": dt.datetime(2020,3,7,18,30),
"user": (123456, "Sonia Meyer", 7038877463), "group_size": 3}
missed_checkout = {"photo": "456.jpg", "date_time": dt.datetime(2020,3,7,23,00),
"user": (123456, "Sonia Meyer", 7038877463), "group_size": 3}
##############################################
##############################################

##############################################
##############################################
def check_user_status(user):
'''the check_user_status function references the database and returns
user status whether they are in or out of the cave'''
if user == "in": return False
if user == "out": return True
##############################################
##############################################

def checked_out():
'''the checked_out will send user a confirmation message'''
client.messages.create(
to='+1'+str(check_in["user"][2]), #user phone number
from_=TWILIO_PHONE_NUMBER,
body='Thanks for visiting {}, you are checked out!'.format(CAVEMANAGER[0])
)
return

def missed_expected_out():
'''the missed_expected_out will check user status at initiate_contact time,
then check with user if they forgot to check out of cave'''
if check_user_status("in"):
return
client.messages.create(
to='+1'+str(check_in["user"][2]), #user phone number
from_=TWILIO_PHONE_NUMBER,
body='Thanks for visiting {}, did you exit with all {} people?'.format(CAVEMANAGER[0],check_in["group_size"])
)
return

def missed_call_out():
'''the missed_call_out will check user status at call out time, then notify
the cave manager to initiate rescue if user is not out'''
if check_user_status("in"):
return
client.messages.create(
to='+1'+str(CAVEMANAGER[2]), #manager phone number
from_=TWILIO_PHONE_NUMBER,
body='{}, {} was visiting {} and did not check out before their call out time of {}.'.format(CAVEMANAGER[1],check_in["user"][1],CAVEMANAGER[0],check_in["call_out"])
)
return
120 changes: 120 additions & 0 deletions WBCarPoolApp/RecommendationAlgorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import googlemaps
from datetime import datetime



ApiKey = ""
# Place Key here

gmaps = googlemaps.Client(key=ApiKey)
# Passes api key to each query

DriverStart = input("Where are you starting from: ")
PassengerLocations = ["Castle Park", "California Citrus State Historic Park","UC Riverside Botanic Gardens","Andulka Park",]
Destination = input("Where are you going: ")
# Collecting data from user as well as defining locations of potenial riders

ExtraMinPerLocation = {
"Castle Park": [] ,
"California Citrus State Historic Park": [],
"UC Riverside Botanic Gardens": [],
"Andulka Park":[],
"Riverside Art Museum": [],
}
ExtraMin = []
# Sets up a dic and list wich will be used for operations later
now = datetime.now()
# Gets current time

for locations in PassengerLocations:
# For every location in the list of passenger locations the following caluclations are completed
OrignalTime = gmaps.directions( DriverStart,
Destination,
optimize_waypoints = True,
mode = "driving",
traffic_model = "best_guess",
departure_time = now)
# Calls first query asking for duration of the drivers orginal dirve
=======
ApiKey=""
# Place Key here

gmaps = googlemaps.Client(key=ApiKey)
DriverStart = input("Where are you starting from: ")
PassengerLocations = ["Fresno", "UCSB","CSUSB","UCSC","Museum of Modern Art"]
Destination = input("Where are you going: ")
ExtraMinPerLocation = {
"Fresno": [] ,
"UCSB": [],
"CSUSB": [],
"UCSC":[],
"Museum of Modern Art": [],

}
ExtraMin = []
now = datetime.now()

for locations in PassengerLocations:
OrignalTime = gmaps.directions( DriverStart,
Destination,
optimize_waypoints = True,
mode = "driving",
traffic_model = "best_guess",
departure_time = now)

Firstleg = gmaps.directions( DriverStart,
locations,
optimize_waypoints = True,
mode = "driving",
traffic_model = "best_guess",
departure_time = now)

Secondleg = gmaps.directions( locations,
Destination,
optimize_waypoints = True,
mode = "driving",
traffic_model = "best_guess",
departure_time = now)

# Second two queries are from drivers start to riders start and riders start to the destination
=======

OrignalTime = OrignalTime[0]['legs'][0]['duration']['value']
FirstLegDuration = Firstleg[0]['legs'][0]['duration']['value']
SecondLegDuration = Secondleg[0]['legs'][0]['duration']['value']

# Parses Data from API
=======

TotalDuration = FirstLegDuration + SecondLegDuration
ExtraTime = TotalDuration - OrignalTime

ExtraMin.append(ExtraTime)
ExtraMinPerLocation[locations].append(ExtraTime)

# Finds how much added time the ride will take and adds it to the list and dic from before
=======



sorted(ExtraMinPerLocation)
ExtraMin.sort()

# Sorts so the shortest time will come first

BestOption = str(next(iter(ExtraMinPerLocation)))
# Grabs the best option from the front of the list

minutes = round(ExtraMin[0] / 60,2)
# Grabs the added time in seconds thne turns it into min and rounds

print(f"There is someone you can pick up at {BestOption}. And it will only add {minutes} minutes to your route!")
# Prints results
=======

BestOption = str(next(iter(ExtraMinPerLocation)))

minutes = round(ExtraMin[0] / 60,2)

print(f"There is someone you can pick up at {BestOption}. And it will only add {minutes} minutes to your route!")

7 changes: 7 additions & 0 deletions WBCarPoolApp/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ('celery_app',)
22 changes: 22 additions & 0 deletions WBCarPoolApp/chat/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chat.settings')

app = Celery('chat')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks(settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
13 changes: 13 additions & 0 deletions WBCarPoolApp/chat/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# chat/models.py

from django.db import models

class Room(models.Model):
"""Represents chat rooms that users can join"""
name = models.CharField(max_length=30)
description = models.CharField(max_length=100)
slug = models.CharField(max_length=50)

def __str__(self):
"""Returns human-readable representation of the model instance."""
return self.name
Loading