Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
semantic_platform_DAS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李明杰
semantic_platform_DAS
Commits
35d7c61e
Commit
35d7c61e
authored
5 years ago
by
李明杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
data read
parent
99f83be6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
+106
-0
bottom_function/data_read.py
bottom_function/data_read.py
+106
-0
No files found.
bottom_function/data_read.py
0 → 100644
View file @
35d7c61e
# -*- coding: utf-8 -*-
# author:Li Mingjie time:2019/1/27
# Brief: read data
import
pandas
as
pd
import
bottom_function.m_SQL
as
qb
import
re
def
read_data
(
datatype
,
starttime
,
endtime
):
csv_data
=
pd
.
DataFrame
()
m_data
=
pd
.
DataFrame
()
tablename
=
"semantic_data_table"
db
=
qb
.
Schema
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"560193"
,
mysqlName
=
"semantic_data_schema"
,
port
=
"3306"
)
csv_data
=
db
.
getData
(
tableName
=
tablename
,
startTime
=
starttime
,
endTime
=
endtime
)
if
datatype
==
"control"
:
m_data
=
csv_data
[
csv_data
[
'classify'
]
==
'gree'
]
elif
datatype
==
"application"
:
m_data
=
csv_data
[
csv_data
[
'classify'
]
==
'tencent'
]
elif
datatype
==
"chat"
:
m_data
=
csv_data
[
csv_data
[
'domain'
]
==
'chat'
]
elif
datatype
==
"all"
:
m_data
=
csv_data
elif
datatype
==
"error_control"
:
m_data
=
db
.
getData
(
tableName
=
"control_error_data"
,
startTime
=
starttime
,
endTime
=
endtime
)
elif
datatype
==
"error_application"
:
m_data
=
db
.
getData
(
tableName
=
"application_error_data"
,
startTime
=
starttime
,
endTime
=
endtime
)
else
:
print
(
"The datatype you selected is incorrect. Please re-select it."
)
return
-
1
return
m_data
def
read_domain_data
(
datatype
,
starttime
,
endtime
):
csv_data
=
pd
.
DataFrame
()
if
datatype
==
"control"
:
tablename
=
"control_domain_data"
db
=
qb
.
Schema
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"560193"
,
mysqlName
=
"semantic_data_schema"
,
port
=
"3306"
)
csv_data
=
db
.
getData
(
tableName
=
tablename
,
startTime
=
starttime
,
endTime
=
endtime
)
elif
datatype
==
"application"
:
tablename
=
"application_domain_data"
db
=
qb
.
Schema
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"560193"
,
mysqlName
=
"semantic_data_schema"
,
port
=
"3306"
)
csv_data
=
db
.
getData
(
tableName
=
tablename
,
startTime
=
starttime
,
endTime
=
endtime
)
elif
datatype
==
"all"
:
db
=
qb
.
Schema
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"560193"
,
mysqlName
=
"semantic_data_schema"
,
port
=
"3306"
)
gcsv_data
=
db
.
getData
(
tableName
=
"control_domain_data"
,
startTime
=
starttime
,
endTime
=
endtime
)
tcsv_data
=
db
.
getData
(
tableName
=
"application_domain_data"
,
startTime
=
starttime
,
endTime
=
endtime
)
tcsv_data
=
tcsv_data
.
drop
(
columns
=
[
'datetime'
])
csv_data
=
pd
.
concat
([
gcsv_data
,
tcsv_data
],
axis
=
1
)
return
csv_data
def
read_cost_time_data
(
datatype
,
starttime
,
endtime
):
csv_data
=
pd
.
DataFrame
()
cost_data
=
pd
.
DataFrame
()
g_data
=
pd
.
DataFrame
()
t_data
=
pd
.
DataFrame
()
gree_dict
=
{}
tencent_dict
=
{}
all_dict
=
{}
time_dict
=
{}
cost_time_dict
=
{}
db
=
qb
.
Schema
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"560193"
,
mysqlName
=
"semantic_data_schema"
,
port
=
"3306"
)
csv_data
=
db
.
getData
(
tableName
=
"cost_time_data"
,
startTime
=
starttime
,
endTime
=
endtime
)
for
col
in
list
(
csv_data
.
columns
)[
1
:]:
gree_dict
.
clear
()
tencent_dict
.
clear
()
all_dict
.
clear
()
time_dict
.
clear
()
for
row
in
range
(
0
,
len
(
csv_data
)):
m_str
=
str
(
csv_data
.
ix
[
row
,
col
])
c
=
re
.
sub
(
'[(),\[\] ]'
,
''
,
m_str
)
str_list
=
c
.
split
(
"'"
)
m_list
=
list
(
filter
(
None
,
str_list
))
if
datatype
==
"control"
:
for
i
in
range
(
0
,
6
,
2
):
if
m_list
[
i
]
in
gree_dict
.
keys
():
gree_dict
[
m_list
[
i
]]
+=
int
(
m_list
[
i
+
1
])
else
:
gree_dict
.
update
({
m_list
[
i
]:
int
(
m_list
[
i
+
1
])})
time_dict
=
gree_dict
.
copy
()
elif
datatype
==
"application"
:
for
j
in
range
(
6
,
12
,
2
):
if
m_list
[
j
]
in
tencent_dict
.
keys
():
tencent_dict
[
m_list
[
j
]]
+=
int
(
m_list
[
j
+
1
])
else
:
tencent_dict
.
update
({
m_list
[
j
]:
int
(
m_list
[
j
+
1
])})
time_dict
=
tencent_dict
.
copy
()
else
:
for
m
in
range
(
0
,
12
,
2
):
if
m_list
[
m
]
in
all_dict
.
keys
():
all_dict
[
m_list
[
m
]]
+=
int
(
m_list
[
m
+
1
])
else
:
all_dict
.
update
({
m_list
[
m
]:
int
(
m_list
[
m
+
1
])})
time_dict
=
all_dict
.
copy
()
sort_data_list
=
sorted
(
time_dict
.
items
(),
key
=
lambda
item
:
item
[
1
],
reverse
=
True
)
cost_time_dict
.
update
({
col
:
sort_data_list
})
return
cost_time_dict
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment