Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nxdblmbackendpython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Alexander Perez
nxdblmbackendpython
Commits
6ff599e5
Commit
6ff599e5
authored
5 years ago
by
Quentin Codelupi
Browse files
Options
Downloads
Patches
Plain Diff
[clean] remove some global vars for flexibility
parent
47ec8f59
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
property_pull.py
+30
-25
30 additions, 25 deletions
property_pull.py
with
30 additions
and
25 deletions
property_pull.py
+
30
−
25
View file @
6ff599e5
...
@@ -18,8 +18,6 @@ import numpy as np
...
@@ -18,8 +18,6 @@ import numpy as np
import
pandas
as
pd
import
pandas
as
pd
_dest_dir
=
'
./pulledData
'
_dest_dir
=
'
./pulledData
'
_files
=
False
_db_write
=
True
# mysqlDB variables
# mysqlDB variables
mydb
=
mysql
.
connector
.
connect
(
mydb
=
mysql
.
connector
.
connect
(
...
@@ -52,8 +50,8 @@ sums_cols = udf(lambda arr: 0 if arr == [] else sum(arr), IntegerType())
...
@@ -52,8 +50,8 @@ sums_cols = udf(lambda arr: 0 if arr == [] else sum(arr), IntegerType())
'''
'''
def
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
):
def
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
,
_files_write
):
if
_files
:
if
_files
_write
:
# Writing output #
# Writing output #
with
open
(
_dest_dir
+
'
/
'
+
_device
+
'
_
'
+
_start_time
.
replace
(
'
'
,
'
_
'
)
+
'
to
'
with
open
(
_dest_dir
+
'
/
'
+
_device
+
'
_
'
+
_start_time
.
replace
(
'
'
,
'
_
'
)
+
'
to
'
+
_end_time
.
replace
(
'
'
,
'
_
'
)
+
'
_
'
+
_property
+
'
.dat
'
,
'
w
'
)
as
outfile
:
+
_end_time
.
replace
(
'
'
,
'
_
'
)
+
'
_
'
+
_property
+
'
.dat
'
,
'
w
'
)
as
outfile
:
...
@@ -75,7 +73,7 @@ def uncompress_pandas(_data_array, _index_array, _size, _nrows):
...
@@ -75,7 +73,7 @@ def uncompress_pandas(_data_array, _index_array, _size, _nrows):
# noinspection SqlResolve
# noinspection SqlResolve
def
pull_histogram_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
):
def
pull_histogram_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
,
_files_write
=
False
,
_db_write
=
True
):
_property
=
'
LoggingHistogram
'
_property
=
'
LoggingHistogram
'
data
=
{}
data
=
{}
...
@@ -150,11 +148,13 @@ def pull_histogram_pandas(_fill_name, _mode, _device, _start_time, _end_time):
...
@@ -150,11 +148,13 @@ def pull_histogram_pandas(_fill_name, _mode, _device, _start_time, _end_time):
db_cursor
=
mydb
.
cursor
()
db_cursor
=
mydb
.
cursor
()
db_cursor
.
execute
(
'
UPDATE Data SET histogram = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
db_cursor
.
execute
(
'
UPDATE Data SET histogram = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
)
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
,
_files_write
)
return
data
# noinspection SqlResolve
# noinspection SqlResolve
def
pull_integral_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
):
def
pull_integral_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
,
_files_write
=
False
,
_db_write
=
True
):
_property
=
"
LoggingIntegral
"
_property
=
"
LoggingIntegral
"
data
=
{}
data
=
{}
...
@@ -233,11 +233,13 @@ def pull_integral_pandas(_fill_name, _mode, _device, _start_time, _end_time):
...
@@ -233,11 +233,13 @@ def pull_integral_pandas(_fill_name, _mode, _device, _start_time, _end_time):
db_cursor
=
mydb
.
cursor
()
db_cursor
=
mydb
.
cursor
()
db_cursor
.
execute
(
'
UPDATE Data SET integral = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
db_cursor
.
execute
(
'
UPDATE Data SET integral = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
)
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
,
_files_write
)
return
data
# noinspection SqlResolve
# noinspection SqlResolve
def
pull_raw_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
):
def
pull_raw_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
,
_files_write
=
False
,
_db_write
=
True
):
_property
=
"
LoggingRawDist
"
_property
=
"
LoggingRawDist
"
data
=
{}
data
=
{}
...
@@ -305,11 +307,13 @@ def pull_raw_dist_pandas(_fill_name, _mode, _device, _start_time, _end_time):
...
@@ -305,11 +307,13 @@ def pull_raw_dist_pandas(_fill_name, _mode, _device, _start_time, _end_time):
db_cursor
=
mydb
.
cursor
()
db_cursor
=
mydb
.
cursor
()
db_cursor
.
execute
(
'
UPDATE Data SET raw_dist = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
db_cursor
.
execute
(
'
UPDATE Data SET raw_dist = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
)
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
,
_files_write
)
return
data
# noinspection SqlResolve
# noinspection SqlResolve
def
pull_integral_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
):
def
pull_integral_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
,
_files_write
=
False
,
_db_write
=
True
):
_property
=
"
LoggingIntegralDist
"
_property
=
"
LoggingIntegralDist
"
data
=
{}
data
=
{}
...
@@ -381,11 +385,13 @@ def pull_integral_dist_pandas(_fill_name, _mode, _device, _start_time, _end_time
...
@@ -381,11 +385,13 @@ def pull_integral_dist_pandas(_fill_name, _mode, _device, _start_time, _end_time
db_cursor
=
mydb
.
cursor
()
db_cursor
=
mydb
.
cursor
()
db_cursor
.
execute
(
'
UPDATE Data SET integral_dist = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
db_cursor
.
execute
(
'
UPDATE Data SET integral_dist = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
)
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
,
_files_write
)
return
data
# noinspection SqlResolve
# noinspection SqlResolve
def
pull_turnloss_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
):
def
pull_turnloss_pandas
(
_fill_name
,
_mode
,
_device
,
_start_time
,
_end_time
,
_files_write
=
False
,
_db_write
=
True
):
_property
=
"
LoggingTurnLoss
"
_property
=
"
LoggingTurnLoss
"
data
=
{}
data
=
{}
...
@@ -463,25 +469,24 @@ def pull_turnloss_pandas(_fill_name, _mode, _device, _start_time, _end_time):
...
@@ -463,25 +469,24 @@ def pull_turnloss_pandas(_fill_name, _mode, _device, _start_time, _end_time):
db_cursor
=
mydb
.
cursor
()
db_cursor
=
mydb
.
cursor
()
db_cursor
.
execute
(
'
UPDATE Data SET turnloss = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
db_cursor
.
execute
(
'
UPDATE Data SET turnloss = %s where id = %s
'
,
(
json
.
dumps
(
data
),
data_id
,))
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
)
write_file
(
_device
,
_start_time
,
_end_time
,
_property
,
data
,
_files_write
)
return
data
def
property_pull
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_input
=
False
,
_db_write_input
=
True
):
global
_files
_files
=
_files_input
global
_db_write
def
property_pull
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_write
=
False
,
_db_write
=
True
):
_db_write
=
_db_write_input
gcursor
=
mydb
.
cursor
()
gcursor
=
mydb
.
cursor
()
gcursor
.
execute
(
'
select count(*) from Mode where name=%s
'
,
(
_mode
,))
gcursor
.
execute
(
'
select count(*) from Mode where name=%s
'
,
(
_mode
,))
mode_exists
=
gcursor
.
fetchone
()[
0
]
mode_exists
=
gcursor
.
fetchone
()[
0
]
if
mode_exists
==
0
:
if
mode_exists
==
0
:
print
(
'
Mode
'
+
_mode
+
'
'
)
print
(
'
Mode
'
+
_mode
+
'
unknown
'
)
gcursor
.
execute
(
'
SELECT id FROM Device where name=%s limit 1
'
,
(
_device
,))
gcursor
.
execute
(
'
SELECT id FROM Device where name=%s limit 1
'
,
(
_device
,))
device_id
=
gcursor
.
fetchone
()[
0
]
device_id
=
gcursor
.
fetchone
()[
0
]
if
device_id
is
None
:
print
(
'
Device
'
+
_device
+
'
unknown
'
)
gcursor
.
execute
(
"
select count(*) from Measure where device_id=%s
"
gcursor
.
execute
(
"
select count(*) from Measure where device_id=%s
"
"
and fill_mode_id in ( select id from FillMode
"
"
and fill_mode_id in ( select id from FillMode
"
...
@@ -514,11 +519,11 @@ def property_pull(_fill_name, _mode, _device, _start, _end, _files_input=False,
...
@@ -514,11 +519,11 @@ def property_pull(_fill_name, _mode, _device, _start, _end, _files_input=False,
'
VALUES ( %s, %s, %s )
'
,
'
VALUES ( %s, %s, %s )
'
,
(
fill_mode_id
,
data_id
,
device_id
))
(
fill_mode_id
,
data_id
,
device_id
))
pull_histogram_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
)
pull_histogram_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_write
,
_db_write
)
pull_integral_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
)
pull_integral_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_write
,
_db_write
)
pull_raw_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
)
pull_raw_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_write
,
_db_write
)
pull_integral_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
)
pull_integral_dist_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_write
,
_db_write
)
pull_turnloss_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
)
pull_turnloss_pandas
(
_fill_name
,
_mode
,
_device
,
_start
,
_end
,
_files_write
,
_db_write
)
mydb
.
commit
()
mydb
.
commit
()
print
(
'
Pulled done, data pushed on DB for fill
'
print
(
'
Pulled done, data pushed on DB for fill
'
...
...
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