-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91e9e89
Showing
11 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pandas as pd | ||
import numpy as np | ||
from pandas import Series, DataFrame | ||
import os | ||
# 데이터 프레임 맞춰준다 | ||
# 6 | ||
# 964 | ||
# test = pd.DataFrame(np.arange(0, 5784).reshape(964, 6)) | ||
# test = test.drop([0]) | ||
# test = test.drop([0], axis=1) | ||
outp = [] | ||
path_dir = '/media/sf_.VirtualBox/em_Data/' | ||
file_list = os.listdir(path_dir) | ||
|
||
for k in file_list: | ||
os.mkdir('/media/sf_.VirtualBox/em/{}'.format(k)) | ||
for i in range(1, 6): | ||
for j in range(1, len(file_list)): | ||
area_df = pd.read_table('/media/sf_.VirtualBox/em_Data/{}/area_s_{}_{}'.format( | ||
k, i, j), sep='\n', engine="python", header=None) | ||
da = area_df.drop([0], axis=0) | ||
x = np.mean(da) | ||
test[i][j] = x | ||
area = DataFrame(test) | ||
area.to_table('/media/sf_VirtualBox/em/{}'.format(k)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from kafka import KafkaConsumer | ||
from json import loads | ||
import pymysql | ||
|
||
mydb = pymysql.connect( | ||
host="13.124.240.211", | ||
user="user", | ||
passwd="12345", | ||
database="SmartInside", | ||
port=51642, | ||
) | ||
sensor_list = [] | ||
consumer1 = KafkaConsumer( | ||
'em', | ||
bootstrap_servers=['smartinside1:9092'], | ||
auto_offset_reset='earliest', | ||
enable_auto_commit=True, | ||
# group_id='my-group', | ||
value_deserializer=lambda x: loads(x.decode('utf-8'))) | ||
for message in consumer1: | ||
a = message.offset | ||
b = message.value | ||
mycursor = mydb.cursor() | ||
sql = "INSERT INTO SmartInside.ke (id,sensor1,sensor2,sensor3,sensor4,sensor5) VALUES (%s,%s,%s,%s,%s,%s)" | ||
val = (a, b["sensor1"], b["sensor2"], | ||
b["sensor3"], b["sensor4"], b["sensor5"]) | ||
mycursor.execute(sql, val) | ||
mydb.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import json | ||
from kafka import KafkaProducer | ||
from kafka import KafkaConsumer | ||
from kafka import KafkaClient | ||
from kafka import TopicPartition | ||
|
||
import msgpack | ||
zookeeper_servers = ["172.20.40.21:2181"] | ||
bootstrap_servers = ["172.20.40.21:9092"] | ||
client = KafkaClient(bootstrap_servers=bootstrap_servers) | ||
producer = KafkaProducer(bootstrap_servers=bootstrap_servers) | ||
producer = KafkaProducer(bootstrap_servers=bootstrap_servers, | ||
value_serializer=lambda v: json.dumps(v).encode('utf-8')) | ||
path_dir = '/media/sf_.VirtualBox/em/' | ||
file_list = os.listdir(path_dir) | ||
for j in file_list: | ||
with open("/media/sf_.VirtualBox/em/{}/em.json".format(j)) as em: | ||
em = json.load(em) | ||
for i in range(0, len(em)): | ||
producer.send("em", em["{}".format(i)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# aftojson em 데이터 json 으로 변환 | ||
# 각 날짜별 폴더의 em 데이터를 json 으로 변환 | ||
|
||
import json | ||
import os | ||
import pandas as pd | ||
|
||
path_dir = '/media/sf_.VirtualBox/em/' | ||
file_list = os.listdir(path_dir) | ||
|
||
for i in file_list: | ||
af = pd.read_table(path_dir+"{}/area_mean".format(i),sep=',',engine="python") | ||
bf=af.drop(['Unnamed: 0'],axis=1) | ||
bf.columns=['sensor1', 'sensor2', 'sensor3', 'sensor4', 'sensor5'] | ||
|
||
result = bf.to_json(orient="index") | ||
json.dumps(result) | ||
em = json.loads(result) | ||
|
||
with open(path_dir+"{}/".format(i)+"em.json", 'w', encoding='utf-8') as make_file: | ||
json.dump(em, make_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from kafka import KafkaConsumer | ||
from json import loads | ||
import pymysql | ||
|
||
mydb = pymysql.connect( | ||
host="13.124.240.211", | ||
user="user", | ||
passwd="12345", | ||
database="SmartInside", | ||
port=51642, | ||
) | ||
consumer1 = KafkaConsumer( | ||
'mfl', | ||
bootstrap_servers=['smartinside1:9092'], | ||
auto_offset_reset='earliest', | ||
enable_auto_commit=True, | ||
# group_id='my-group', | ||
value_deserializer=lambda x: loads(x.decode('utf-8'))) | ||
|
||
for message in consumer1: | ||
a = message.offset | ||
b = message.value | ||
mycursor = mydb.cursor() | ||
sql = "INSERT INTO SmartInside.km (id,sensor1,sensor2,sensor3,sensor4,sensor5,sensor6) VALUES (%s,%s,%s,%s,%s,%s,%s)" | ||
|
||
val = (a, b["sensor1"], b["sensor2"], b["sensor3"], | ||
b["sensor4"], b["sensor5"], b["sensor6"]) | ||
mycursor.execute(sql, val) | ||
mydb.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
from kafka import KafkaProducer | ||
from kafka import KafkaConsumer | ||
from kafka import KafkaClient | ||
from kafka import TopicPartition | ||
import msgpack | ||
|
||
zookeeper_servers = ["172.20.40.21:2181"] | ||
bootstrap_servers = ["172.20.40.21:9092"] | ||
client = KafkaClient(bootstrap_servers=bootstrap_servers) | ||
producer = KafkaProducer(bootstrap_servers=bootstrap_servers, | ||
value_serializer=lambda v: json.dumps(v).encode('utf-8')) | ||
|
||
with open("/media/sf_.VirtualBox/mfl/20210507/mfl.json") as mfl: | ||
mfl = json.load(mfl) | ||
for i in range(1, len(mfl)): | ||
producer.send("mfl", mfl["{}".format(i)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import pandas as pd | ||
|
||
origin_df = pd.read_table('td50.lvm', sep ='\t', engine="python" ,header=None) | ||
new_col = ["space","sensor1","sensor2","sensor3","sensor4","sensor5","sensor6","sensor7","sensor8","sensor9","sensor10"] | ||
origin_df.columns = new_col | ||
reshape_df=origin_df.drop(columns=["space"]) | ||
reshape_df.to_csv('td50_reshape.lvm', index=False,sep="\t") |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from matplotlib import colors as mcolors ## 첫번째 프로토타입 | ||
import matplotlib.pyplot as plt ## 그래프, 동영상 업로딩 용이 | ||
## | ||
from matplotlib.collections import PolyCollection | ||
from mpl_toolkits.mplot3d import Axes3D | ||
# import comedata1 as cd1 | ||
import altair as alt | ||
import streamlit as st | ||
import numpy as np | ||
import pandas as pd | ||
import comedata as cd | ||
|
||
|
||
MFL_df = cd.MFLdf | ||
AREA_df = cd.AREAdf | ||
MFL_df1 = MFL_df.drop('id', axis=1) | ||
AREA_df1 = AREA_df.drop('id', axis=1) | ||
|
||
|
||
def main(): | ||
st.title("PROJECT") | ||
st.write("\n") | ||
st.write("센서데이터 활용 건설안전을 위한 신호분석 및 모델링 프로젝트입니다") | ||
st.write("\t\a멘토 -신주호") | ||
st.write("\n") | ||
st.write("\t\a조원 - 김용준,배형근,변영준") | ||
st.write("\n") | ||
st.write("\t\a프로젝트 기간 - 2021년 3월 8일 ~ 2021년 5월 18일") | ||
st.image('C:\\Users\\kyjoo\\Desktop\\산학자료\\code\\streamlit\\cone.jpg') | ||
|
||
|
||
def MFL(): | ||
st.title("MFL Data") | ||
st.write("\n") | ||
sensor_list = MFL_df1.columns.unique() | ||
sensors = st.multiselect( | ||
"센서 선택", list(sensor_list)), [ | ||
sensor_list[0], sensor_list[1]] | ||
|
||
st.line_chart(MFL_df1) | ||
if st.checkbox('Show dataframe'): | ||
st.dataframe(MFL_df1) | ||
st.image("C:\\Users\\kyjoo\\Desktop\\산학자료\\image\\\m1.jpg") | ||
|
||
|
||
def AREA(): | ||
st.title("AREA Data") | ||
st.write("\n") | ||
|
||
st.line_chart(AREA_df1) | ||
if st.checkbox('Show dataframe'): | ||
st.dataframe(AREA_df1) | ||
|
||
|
||
def DETECT(): | ||
st.video('C:\\Users\\kyjoo\\Desktop\\산학자료\\code\\streamlit\\detect.mp4') | ||
|
||
|
||
options = st.sidebar.selectbox('센서데이터', ['main', 'MFL', 'AREA', 'DETECT']) | ||
|
||
if options == 'main': | ||
main() | ||
elif options == 'MFL': | ||
MFL() | ||
elif options == 'AREA': | ||
AREA() | ||
elif options == 'DETECT': | ||
DETECT() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
from matplotlib import colors as mcolors # 두번째 프로토타입 | ||
import matplotlib.pyplot as plt # 대시보드 | ||
from matplotlib.collections import PolyCollection | ||
from mpl_toolkits.mplot3d import Axes3D | ||
import streamlit.components.v1 as components | ||
import altair as alt | ||
import streamlit as st | ||
import numpy as np | ||
import pandas as pd | ||
import comedata as cd | ||
import matplotlib.animation as animation | ||
import cv2 | ||
# from streamlit_webrtc import webrtc_streamer | ||
|
||
|
||
MFL_df = cd.MFLdf | ||
AREA_df = cd.AREAdf | ||
MFL_df1 = MFL_df.drop('id', axis=1) | ||
AREA_df1 = AREA_df.drop('id', axis=1) | ||
video_file = open( | ||
'C:\\Users\\kyjoo\\Desktop\\smartinside\\code\\streamlit\\demo_output.mp4', 'rb') | ||
video_bytes2 = video_file.read() | ||
video_file = open( | ||
"C:\\Users\\kyjoo\\Desktop\\smartinside\\code\\gitadd\\streamlit\\workman.mp4", 'rb') | ||
video_bytes = video_file.read() | ||
|
||
|
||
def main(): | ||
st.title("건설안전-작업자현황 및 안전감시 시스템") | ||
st.write("\n") | ||
cols = st.beta_columns(4) | ||
cols[0].write("현재 작업인원: {}".format(20)) | ||
cols[1].write("경고(2명이상): {}".format("삐용")) | ||
|
||
st.sidebar.markdown(f''' | ||
<div class="card text-white bg-info mb-3" style="width: 18rem"> | ||
<div class="card-body"> | ||
<h5 class="card-title">Total Worker : {20}\n</h5> | ||
<h5 class="card-text">Warning : {1}</h5> | ||
</div> | ||
</div>''', unsafe_allow_html=True) | ||
|
||
if 3 >= 2: | ||
st.warning("작업환경이 위험합니다.") | ||
|
||
fig = plt.figure(figsize=(22, 3)) | ||
|
||
times_work = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] | ||
tn_work = [15, 16, 15, 14, 15, 16, 17, 18, 17, 17, 14, 6] | ||
tn_warn = [1, 1, 1, 2, 3, 4, 3, 2, 0, 1, 1, 1] | ||
ax = fig.add_subplot(1, 2, 1) | ||
bx = fig.add_subplot(1, 2, 2) | ||
ax.bar( | ||
times_work, | ||
tn_work | ||
) | ||
bx.bar( | ||
times_work, | ||
tn_warn | ||
) | ||
bx.set_xlabel("time") | ||
bx.set_ylabel("warning") | ||
ax.set_xlabel("time") | ||
ax.set_ylabel("workers") | ||
|
||
st.pyplot(fig) | ||
|
||
|
||
def MFL(): | ||
st.title("MFL Data") | ||
st.write("\n") | ||
# sensor_list = MFL_df1.columns.unique() | ||
# sensors = st.multiselect( | ||
# "센서 선택", list(sensor_list)), [ | ||
# sensor_list[0], sensor_list[1]] | ||
|
||
st.line_chart(MFL_df1) | ||
if st.checkbox('Show dataframe'): | ||
st.dataframe(MFL_df1) | ||
|
||
|
||
def AREA(): | ||
st.title("AREA Data") | ||
st.write("\n") | ||
|
||
st.line_chart(AREA_df1) | ||
if st.checkbox('Show dataframe'): | ||
st.dataframe(AREA_df1) | ||
|
||
|
||
def DETECT(): | ||
st.title("DETECTING") | ||
|
||
st.video(video_bytes) | ||
|
||
|
||
options = st.sidebar.selectbox('센서데이터', ['PROJECT', 'MFL', 'AREA', 'DETECT']) | ||
|
||
if options == 'PROJECT': | ||
main() | ||
elif options == 'MFL': | ||
MFL() | ||
elif options == 'AREA': | ||
AREA() | ||
elif options == 'DETECT': | ||
DETECT() | ||
|
||
|
||
if st.sidebar.button("작업장"): | ||
st.video(video_bytes2) | ||
|
||
# if st.sidebar.button("커멘드"): | ||
# run = st.checkbox('Run') | ||
# FRAME_WINDOW = st.image([]) | ||
# camera = cv2.VideoCapture(0) | ||
# while run: | ||
# _, frame = camera.read() | ||
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | ||
# FRAME_WINDOW.image(frame) | ||
# else: | ||
# webrtc_streamer(key="example") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pymysql | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
sensor_db = pymysql.connect( | ||
user="user", | ||
passwd="12345", | ||
host="13.124.240.211", | ||
db="SmartInside", | ||
port=51642, | ||
charset='utf8' | ||
) | ||
cursor = sensor_db.cursor(pymysql.cursors.DictCursor) | ||
|
||
mflsql = "select * from `MFL`;" | ||
areasql = "select * from `AREA`;" | ||
# sql = "load data local infile 'td50_reshape.lvm' into table sensor columns terminated by '\t' ignore 1 lines;" | ||
# cursor.execute(selectsql) | ||
cursor.execute(mflsql) | ||
mflresult = cursor.fetchall() | ||
|
||
cursor.execute(areasql) | ||
arearesult = cursor.fetchall() | ||
|
||
|
||
MFLaf = pd.DataFrame(mflresult) | ||
MFLdf = MFLaf.astype(float) | ||
AREAdf = pd.DataFrame(arearesult) |