Skip to content

Commit

Permalink
1、增加显示机动车、非机动车、行人等数据信息
Browse files Browse the repository at this point in the history
2、优化excle表格显示
  • Loading branch information
xiaoweihong committed May 16, 2018
1 parent ceafbb4 commit c9ac9d7
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 5 deletions.
58 changes: 58 additions & 0 deletions monitor/DeepDataPgInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/5/16 下午2:21
# @Author : xiaowei
# @Site :
# @File : DeepDataPgInfo.py
# @Software: PyCharm
import psycopg2

class DeepVideoPostgresTool:
def __init__(self,database,host):
self.database=database
self.user='postgres'
self.password='123456'
self.host=host
self.port="5432"

def getConnect(self):
conn=psycopg2.connect(database=self.database,user=self.user,password=self.password,host=self.host,port=self.port)
return conn

def getVehicle(self):
conn=self.getConnect()
cur=conn.cursor()
cur.execute("SELECT COUNT(*) FROM VEHICLES")
vehicles=cur.fetchall()
conn.close()
return vehicles

def getNonmontor(self):
conn=self.getConnect()
cur=conn.cursor()
cur.execute("SELECT COUNT(*) FROM NONMOTORS")
nonmotors=cur.fetchall()
conn.close()
return nonmotors

def getPedestrians(self):
conn=self.getConnect()
cur=conn.cursor()
cur.execute("SELECT COUNT(*) FROM PEDESTRIANS")
pedestrians=cur.fetchall()
conn.close()
return pedestrians

def getDeepDataInfo(self):
deepdata = {"vehicles": None, "nonmotors": None, "pedestrians": None}
deepdata["vehicles"]=self.getVehicle()[0][0]
deepdata["nonmotors"]=self.getNonmontor()[0][0]
deepdata["pedestrians"]=self.getPedestrians()[0][0]
return deepdata

if __name__=='__main__':
pg=DeepVideoPostgresTool(database='deepdata_v6',host="192.168.2.158")
print(pg.getVehicle()[0][0])
print(pg.getNonmontor())
print(pg.getPedestrians())
print(pg.getDeepDataInfo())
21 changes: 20 additions & 1 deletion monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import xlwt
from HostInfo import GetInfos
from ExcleStyle import Excle_tool
from DeepDataPgInfo import DeepVideoPostgresTool
from collections import OrderedDict
import time
localTime = time.localtime(time.time())
database="deepdata_v6"
host="192.168.2.158"
#strTime = time.strftime("%Y%m%d%H%M%S", localTime)
strTime = time.strftime("%Y%m%d", localTime)
filename=strTime+'.xls'
book=xlwt.Workbook(encoding='utf-8',style_compression=0)

sheet0=book.add_sheet('数据统计',cell_overwrite_ok=True)
sheet1=book.add_sheet('主机信息',cell_overwrite_ok=True)
sheet2=book.add_sheet('内存信息',cell_overwrite_ok=True)
sheet3=book.add_sheet('GPU使用率',cell_overwrite_ok=True)
Expand All @@ -31,7 +35,8 @@
network_receive_content=[]
network_transmit_content=[]


data_table_info=DeepVideoPostgresTool(database=database,host=host).getDeepDataInfo()
data_table_title=["机动车","非机动车","行人"]

json_disk_info=GetInfos().getDiskInfo()
disk_infos=json_disk_info['data']['result']
Expand All @@ -58,21 +63,30 @@
network_transmit_table_title=GetInfos().getTitle(network_transmit_infos)


for i in range(len(data_table_title)):
sheet0.col(i).width=256*30
sheet0.write(0,i,data_table_title[i],Excle_tool().def_style(320))

for i in range(len(disk_table_title)):
sheet1.col(i).width=256*30
sheet1.write(0,i,disk_table_title[i],Excle_tool().def_style(320))

for i in range(len(mem_table_title),):
sheet2.col(i).width=256*30
sheet2.write(0,i,mem_table_title[i],Excle_tool().def_style(320))

for i in range(len(gpu_table_title)):
sheet3.col(i).width=256*30
sheet3.write(0,i,gpu_table_title[i],Excle_tool().def_style(320))

for i in range(len(gpu_mem_table_title)):
sheet4.col(i).width=256*30
sheet4.write(0,i,gpu_mem_table_title[i],Excle_tool().def_style(320))

for i in range(len(network_receive_table_title)):
sheet5.col(i).width=256*30
sheet5.write(0,i,network_receive_table_title[i],Excle_tool().def_style(320))

for i in range(len(network_transmit_table_title)):
sheet6.col(i).width=256*30
sheet6.write(0,i,network_transmit_table_title[i],Excle_tool().def_style(320))
Expand Down Expand Up @@ -121,6 +135,11 @@
hostInfo['value']=value[1]+"GB"
network_transmit_content.append(list(hostInfo.values()))

print("正在导出数据信息....")
print(list(data_table_info.values()))
for row in range(len(list(data_table_info.values()))):
sheet0.write(1,row,list(data_table_info.values())[row],Excle_tool().def_style(320,False))

print("正在导出disk信息....")
for row in range(len(disk_content)):
for col in range(0,len(disk_content[row])):
Expand Down
39 changes: 35 additions & 4 deletions postgres_exporter/VehiclesInfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,39 @@

date_now=$(date +%F)
date_tomorrow=$(date -d tomorrow +%F)
vehicles_temp=`su - postgres -c"psql -d deepdata_v6 << eof
select count(*) from vehicles where uts > '$date_now' and uts < '$date_tomorrow';
function getVehicles(){
vehicles_temp2=`su - postgres -c"psql -d deepdata_v6 << eof
explain analyze select count(*) from vehicles where uts > '$date_now' and uts < '$date_tomorrow';
eof"`
vehicles_count_1=`echo $vehicles_temp|awk '{print $3}'`
echo $vehicles_count_1

vehicles_count_2=`echo $vehicles_temp2|awk -F 'actual time' '{print $3}'|awk '{print $2}'|awk -F '=' '{print $2}'`

}
#vehicles_temp1=`su - postgres -c"psql -d deepdata_v6 << eof
#select count(*) from vehicles where uts > '$date_now' and uts < '$date_tomorrow';
#eof"`
#vehicles_count_1=`echo $vehicles_temp1|awk '{print $3}'`
#echo $vehicles_count_1

function getPedestrians(){
pedestrians_temp2=`su - postgres -c"psql -d deepdata_v6 << eof
explain analyze select count(*) from pedestrians where uts > '$date_now' and uts < '$date_tomorrow';
eof"`

pedestrians_count_2=`echo $pedestrians_temp2|awk -F 'actual time' '{print $3}'|awk '{print $2}'|awk -F '=' '{print $2}'`
}

function getNonmotors(){
nonmotors_temp2=`su - postgres -c"psql -d deepdata_v6 << eof
explain analyze select count(*) from nonmotors where uts > '$date_now' and uts < '$date_tomorrow';
eof"`

nonmotors_count_2=`echo $nonmotors_temp2|awk -F 'actual time' '{print $3}'|awk '{print $2}'|awk -F '=' '{print $2}'`
}

getVehicles
getPedestrians
getNonmotors
echo $vehicles_count_2
echo $nonmotors_count_2
echo $pedestrians_count_2

0 comments on commit c9ac9d7

Please sign in to comment.