Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BigData-radio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ANDRE Quentin
BigData-radio
Commits
52514a77
Commit
52514a77
authored
3 years ago
by
Quentin ANDRE
Browse files
Options
Downloads
Patches
Plain Diff
consumer and producer
parent
a2768f1d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
planes.py
+7
-3
7 additions, 3 deletions
planes.py
planes_consumer.py
+21
-0
21 additions, 0 deletions
planes_consumer.py
planes_producer.py
+22
-0
22 additions, 0 deletions
planes_producer.py
trains.py
+0
-27
0 additions, 27 deletions
trains.py
useful-sh.sh
+4
-1
4 additions, 1 deletion
useful-sh.sh
with
54 additions
and
31 deletions
planes.py
+
7
−
3
View file @
52514a77
from
time
import
sleep
from
time
import
sleep
,
time
import
json
from
opensky_api
import
OpenSkyApi
...
...
@@ -9,8 +9,12 @@ producer = KafkaProducer(bootstrap_servers="pi-node07:9092")
api
=
OpenSkyApi
()
while
1
:
states
=
api
.
get_states
()
producer
.
send
(
"
air-traffic
"
,
json
.
dumps
(
states
).
encode
())
print
(
"
{} Produced {} air traffic records
"
.
format
(
time
.
time
(),
len
(
states
)))
for
state
in
states
.
states
:
plane
=
{
'
time
'
:
states
.
time
}
for
key
in
state
.
keys
:
plane
[
key
]
=
getattr
(
state
,
key
)
producer
.
send
(
"
air-traffic
"
,
json
.
dumps
(
plane
).
encode
())
print
(
"
{} Produced {} air traffic records
"
.
format
(
time
(),
len
(
states
.
states
)))
sleep
(
10.01
)
...
...
This diff is collapsed.
Click to expand it.
planes_consumer.py
0 → 100644
+
21
−
0
View file @
52514a77
import
json
from
kafka
import
KafkaConsumer
planes
=
{}
consumer
=
KafkaConsumer
(
"
air-traffic
"
,
bootstrap_servers
=
'
pi-node07:9092
'
,
group_id
=
"
air-traffic-monitor
"
)
for
message
in
consumer
:
print
(
message
)
'''
plane = json.loads(message.value.decode())
plane_number = plane[
"
number
"
]
contract = plane[
"
contract_name
"
]
available_bike_stands = plane[
"
available_bike_stands
"
]
if contract not in planes:
planes[contract] = {}
city_planes = planes[contract]
if plane_number not in city_planes:
city_planes[plane_number] = available_bike_stands
count_diff = available_bike_stands - city_planes[plane_number]
if count_diff != 0:
city_planes[plane_number] = available_bike_stands
print(
"
{}{} {} ({})
"
.format(
"
+
"
if count_diff > 0 else
""
,count_diff, plane[
"
address
"
], contract))
'''
\ No newline at end of file
This diff is collapsed.
Click to expand it.
planes_producer.py
0 → 100644
+
22
−
0
View file @
52514a77
from
time
import
sleep
,
time
import
json
from
opensky_api
import
OpenSkyApi
from
kafka
import
KafkaProducer
producer
=
KafkaProducer
(
bootstrap_servers
=
"
pi-node07:9092
"
)
api
=
OpenSkyApi
()
while
1
:
states
=
api
.
get_states
()
for
state
in
states
.
states
:
plane
=
{
'
time
'
:
states
.
time
}
for
key
in
state
.
keys
:
plane
[
key
]
=
getattr
(
state
,
key
)
producer
.
send
(
"
air-traffic
"
,
json
.
dumps
(
plane
).
encode
())
print
(
"
{} Produced {} air traffic records
"
.
format
(
time
(),
len
(
states
.
states
)))
sleep
(
10.01
)
if
__name__
==
'
__main__
'
:
pass
This diff is collapsed.
Click to expand it.
trains.py
deleted
100644 → 0
+
0
−
27
View file @
a2768f1d
from
time
import
sleep
from
opensky_api
import
OpenSkyApi
api
=
OpenSkyApi
()
states
=
api
.
get_states
()
sleep
(
12
)
states2
=
api
.
get_states
()
print
(
len
(
states
.
states
))
print
(
len
(
states2
.
states
))
ids
=
set
()
ids2
=
set
()
for
s
in
states
.
states
:
ids
.
add
(
s
.
icao24
)
for
s
in
states2
.
states
:
ids2
.
add
(
s
.
icao24
)
print
(
len
(
ids
-
ids2
)
+
len
(
ids2
-
ids
))
'''
for s in states.states:
print(
"
(%r, %r, %r, %r, %r)
"
% (s.longitude, s.latitude, s.baro_altitude, s.geo_altitude, s.velocity))
for s in states2.states:
print(
"
(%r, %r, %r, %r, %r)
"
% (s.longitude, s.latitude, s.baro_altitude, s.geo_altitude, s.velocity))
'''
if
__name__
==
'
__main__
'
:
pass
This diff is collapsed.
Click to expand it.
useful-sh.sh
+
4
−
1
View file @
52514a77
...
...
@@ -10,4 +10,7 @@ rm -rf /tmp/zookeeper/
ls
/opt/kafka-data/
sudo rm
-rf
/opt/kafka-data/
sudo mkdir
/opt/kafka-data/
sudo chown
-R
pi:pi /opt/kafka-data
\ No newline at end of file
sudo chown
-R
pi:pi /opt/kafka-data
# listen to a node
nc pi-node07 9092
\ No newline at end of file
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