Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
jr
Commits
c78bb0f0
Commit
c78bb0f0
authored
Jul 18, 2024
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Client: Graph: Add trips
parent
a89c68b6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
prog/graph.py
+71
-5
71 additions, 5 deletions
prog/graph.py
with
71 additions
and
5 deletions
prog/graph.py
+
71
−
5
View file @
c78bb0f0
...
@@ -8,6 +8,11 @@ from qgis.PyQt.QtWidgets import *
...
@@ -8,6 +8,11 @@ from qgis.PyQt.QtWidgets import *
from
qgis.PyQt.QtCore
import
*
from
qgis.PyQt.QtCore
import
*
from
qgis.PyQt.QtGui
import
*
from
qgis.PyQt.QtGui
import
*
import
gtfs
from
qasync
import
QEventLoop
,
asyncClose
,
asyncSlot
,
QApplication
import
asyncio
import
numpy
as
np
import
numpy
as
np
from
matplotlib.backends.backend_qtagg
import
FigureCanvas
from
matplotlib.backends.backend_qtagg
import
FigureCanvas
...
@@ -31,21 +36,37 @@ class Graph(QWidget):
...
@@ -31,21 +36,37 @@ class Graph(QWidget):
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
layout
=
QVBoxLayout
()
self
.
_
layout
=
QVBoxLayout
()
self
.
setLayout
(
layout
)
self
.
setLayout
(
self
.
_
layout
)
canvas
=
FigureCanvas
(
Figure
(
figsize
=
(
5
,
3
)))
canvas
=
FigureCanvas
(
Figure
(
figsize
=
(
5
,
3
)))
layout
.
addWidget
(
canvas
)
self
.
_
layout
.
addWidget
(
canvas
)
layout
.
addWidget
(
NavigationToolbar
(
canvas
,
self
))
self
.
_
layout
.
addWidget
(
NavigationToolbar
(
canvas
,
self
))
self
.
ax
=
canvas
.
figure
.
subplots
()
self
.
ax
=
canvas
.
figure
.
subplots
()
class
HistoryGraph
(
Graph
):
class
HistoryGraph
(
Graph
):
def
__init__
(
self
,
stops
):
def
__init__
(
self
,
stops
,
default_line
=
None
,
default_dt_from
=
None
,
default_dt_to
=
None
):
super
().
__init__
()
super
().
__init__
()
self
.
_add_layout
=
QHBoxLayout
()
self
.
_layout
.
insertLayout
(
0
,
self
.
_add_layout
)
self
.
_add_selector
=
QLineEdit
(
str
(
default_line
)
if
default_line
else
""
)
self
.
_add_layout
.
addWidget
(
self
.
_add_selector
)
self
.
_add_selector
.
returnPressed
.
connect
(
self
.
process_add
)
self
.
_add_dt_from
=
QLineEdit
(
format_dt_to_user
(
default_dt_from
or
datetime
.
datetime
.
now
(
local_timezone
)
-
datetime
.
timedelta
(
hours
=
2
)))
self
.
_add_layout
.
addWidget
(
self
.
_add_dt_from
)
self
.
_add_dt_from
.
returnPressed
.
connect
(
self
.
process_add
)
self
.
_add_dt_to
=
QLineEdit
(
format_dt_to_user
(
default_dt_to
or
datetime
.
datetime
.
now
(
local_timezone
)))
self
.
_add_layout
.
addWidget
(
self
.
_add_dt_to
)
self
.
_add_dt_to
.
returnPressed
.
connect
(
self
.
process_add
)
self
.
_add_button
=
QPushButton
(
"
Add
"
)
self
.
_add_layout
.
addWidget
(
self
.
_add_button
)
self
.
_add_button
.
clicked
.
connect
(
self
.
process_add
)
xticks
=
[]
xticks
=
[]
xlabels
=
[]
xlabels
=
[]
for
stop
in
stops
:
for
stop
in
stops
:
...
@@ -97,3 +118,48 @@ class HistoryGraph(Graph):
...
@@ -97,3 +118,48 @@ class HistoryGraph(Graph):
self
.
_line
.
figure
.
canvas
.
draw
()
self
.
_line
.
figure
.
canvas
.
draw
()
@asyncSlot
()
async
def
process_add
(
self
):
selector
=
self
.
_add_selector
.
text
()
dt_from
=
parse_dt_from_user
(
self
.
_add_dt_from
.
text
())
dt_to
=
parse_dt_from_user
(
self
.
_add_dt_to
.
text
())
g
=
gtfs
.
for_date
(
dt_from
)
await
g
.
load_trips
()
trips
=
[
Trip
(
id
,
g
.
date
)
for
id
,
t
in
g
.
trips
.
items
()
if
id
.
startswith
(
selector
+
"
_
"
)]
ths
=
{
t
.
trip_id
:
TripHistory
(
t
)
for
t
in
trips
}
route_ids
=
{
trip
.
trip_id
.
split
(
"
_
"
)[
0
]
for
trip
in
trips
}
print
(
route_ids
)
c
=
await
get_communication
()
for
route_id
in
route_ids
:
dt
=
dt_from
.
replace
(
second
=
0
,
microsecond
=
0
,
minute
=
0
)
while
dt
<
dt_to
:
data
,
source_timestamps
=
await
c
.
get_preprocessed_data
(
dt
,
route_id
)
print
(
"
P1
"
)
data
=
await
unzip_parse
(
data
)
print
(
"
P3
"
)
for
trip_id
,
th
in
ths
.
items
():
if
trip_id
in
data
:
th
.
add_preprocessed_data
(
data
[
trip_id
])
dt
+=
datetime
.
timedelta
(
hours
=
1
)
print
(
"
P4
"
)
for
route_id
in
route_ids
:
stops_data
=
await
c
.
gtfs_get_stop_times
(
dt_from
,
route_filter
=
route_id
)
for
trip_id
,
th
in
ths
.
items
():
if
trip_id
.
split
(
"
_
"
)[
0
]
==
route_id
:
await
th
.
load_stops
(
stops_data
)
for
th
in
ths
.
values
():
if
len
(
th
.
history
):
print
(
"
ADD TRIP
"
)
self
.
add_trip
(
th
)
print
(
"
DONE
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment