Skip to content

Commit

Permalink
v1.5.0 stops page
Browse files Browse the repository at this point in the history
  • Loading branch information
answerquest committed Aug 31, 2019
1 parent 9ec455c commit b239d07
Show file tree
Hide file tree
Showing 25 changed files with 14,952 additions and 228 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
routes
locked-routes
reports
logs
gtfs


routes-backup-30.7.19
__pycache__
routes-temp
shelved
datacleaning
2 changes: 0 additions & 2 deletions allMap.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
<li><a href="https://github.com/Turbo87/sidebar-v2" role="tab" target="_blank"><i class="fa fa-github"></i></a></li>
-->
</ul>

<ul role="tablist">
<li><a href="#settings" role="tab"><i class="fa fa-gear"></i></a></li>
</ul>
Expand All @@ -116,7 +115,6 @@ <h1 class="sidebar-header">
<div class="sidebar-pane" id="profile">
<h2 class="sidebar-header">Profile<span class="sidebar-close"><i class="fa fa-caret-left"></i></span></h2>
</div>
<div class="sidebar-pane" id="messages">
<h1 class="sidebar-header">Messages<span class="sidebar-close"><i class="fa fa-caret-left"></i></span></h1>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"Mapped Stops": "reports/stops_mapped.csv",
"Automapped Stops": "reports/stops_automapped.csv"
},
"version": "v1.4.0"
"version": "v1.5.0"
}
3 changes: 1 addition & 2 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ def saveDataEntryRoute(filename,data={}, key=False):
routeD['extra1'] = data.get('extra1','')
changesMade = True


# and now we proceed to <gulp> rewrite the stop sequences!
# don't worry, backups happening. Damn gotta have an easy way to restore backups..

Expand Down Expand Up @@ -742,7 +741,7 @@ def saveDataEntryRoute(filename,data={}, key=False):


# logmessage(json.dumps(routeD, indent=2))

# ''' # uncomment when ready
if changesMade and key:
info = userInfo(key)
Expand Down
44 changes: 35 additions & 9 deletions gtfs_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def timeFormat(x):
justnum = holder1[0]
if justnum == '':
# blank string
return False
return ''
if len(justnum) in [3,4]:
holder1 = [ justnum[:-2], justnum[-2:] ]
print("Special case: {} becomes {}".format(justnum,holder1))
else:
print('{} is an invalid time string.'.format(x))
raise ValueError("'{}' is an invalid time string.".format(x))
print('{} is an invalid time string. Skipping it.'.format(x))
# raise ValueError("'{}' is an invalid time string.".format(x))
return ''
hh = holder1[0].rjust(2,'0')
mm = holder1[1].rjust(2,'0')
if len(holder1) >= 3: ss = holder1[2].rjust(2,'0')
Expand All @@ -64,9 +65,9 @@ def time2secs(hhmmss):
if len(holder1) < 2:
print('{} is an invalid time string.'.format(hhmmss))
raise ValueError("'{}' is an invalid time string.".format(hhmmss))
hh = int(holder1[0])
mm = int(holder1[1])
if len(holder1) >= 3: ss = int(holder1[2])
hh = int(float(holder1[0]))
mm = int(float(holder1[1]))
if len(holder1) >= 3: ss = int(float(holder1[2])) # taking precautions for cases like '0.0' - first parse float, then int
else: ss = 0
return (hh*3600 + mm*60 + ss)
# test:
Expand All @@ -75,14 +76,15 @@ def time2secs(hhmmss):
# print\( time2secs('00:05:34') )

def secs2time(secs):
# data cleaning: secs must be int
secs = int(float(secs))
hh = str(int(secs/3600)).rjust(2,'0')
remaining = secs % 3600
mm = str(int(remaining/60)).rjust(2,'0')
ss = str(remaining % 60).rjust(2,'0')

return "{}:{}:{}".format(hh,mm,ss)
# test
# print\(secs2time(3453))
# print(secs2time(3453))

def timeDiff(t1,t2,formatted=True):
diff = time2secs(t2) - time2secs(t1)
Expand Down Expand Up @@ -152,6 +154,28 @@ def timeEngine(first_trip_start,last_trip_start,trip_duration,num_trips):
# cross midnight?
# print\('crossing midnight example:\n',timeEngine('23:30', '01:10','01:00',5))

def timeEngineFrequency(first_trip_start,last_trip_start,frequency,trip_duration):
# +24h if last time crosses midnight
if time2secs(last_trip_start) <= time2secs(first_trip_start):
last_trip_start = timeAdd(last_trip_start,24*60*60)

headway = frequency

first_trip_end = timeAdd(first_trip_start,time2secs(trip_duration))
last_trip_end = timeAdd(last_trip_start,time2secs(trip_duration))

num_trips = timeDiff(first_trip_start,last_trip_start,formatted=False) // headway

tripTimesArray = []
for n in range(num_trips):
start_time = timeAdd(first_trip_start,round(n*headway) )
end_time = timeAdd(first_trip_end,round(n*headway) )
tripTimesArray.append( [start_time,end_time] )

# and add the last trip at end
tripTimesArray.append( [last_trip_start,last_trip_end] )

return tripTimesArray.copy()

# In[12]:

Expand All @@ -160,7 +184,9 @@ def tripTimesProcess(timestr):
timestr2 = timestr.replace(' ','|').replace(',','|')
holder = [timeFormat(x) for x in timestr2.split('|') if len(x)]
# print(holder)
return holder
# in case any element in holder is ''
holder2 = [x for x in holder if len(x)]
return holder2

# test
tripTimesProcess('05:15,05:50,06:15,06:35,07:55,08:35,09:30,10:05,10:25,11:40,12:35,13:20,14:15,14:40,15:30,16:20,17:05,17:30,18:25,18:45 ,19:10,20:50,21:10,21:45')
Expand Down
Loading

0 comments on commit b239d07

Please sign in to comment.