Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
core_tools
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QuTech QDLabs
core_tools
Commits
2e225df0
Commit
2e225df0
authored
2 years ago
by
Sander Snoo
Browse files
Options
Downloads
Patches
Plain Diff
Added get_history
parent
799e8a7d
No related branches found
Branches containing commit
Tags
v1.4.3
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core_tools/utility/variable_mgr/var_mgr.py
+37
-2
37 additions, 2 deletions
core_tools/utility/variable_mgr/var_mgr.py
core_tools/utility/variable_mgr/var_mgr_sql.py
+27
-5
27 additions, 5 deletions
core_tools/utility/variable_mgr/var_mgr_sql.py
with
64 additions
and
7 deletions
core_tools/utility/variable_mgr/var_mgr.py
+
37
−
2
View file @
2e225df0
...
...
@@ -104,6 +104,12 @@ class variable_mgr():
else
:
print
(
f
'
trying to add variable
{
name
}
that is already there
'
)
def
get_history
(
self
,
variable_name
):
if
hasattr
(
self
,
variable_name
):
return
var_sql_queries
.
get_history
(
variable_mgr
().
conn_local
,
variable_name
)
else
:
print
(
f
'
trying to fetch history of a variable
{
variable_name
}
that does not exist.
'
)
def
remove_variable
(
self
,
variable_name
):
obj
=
super
().
__getattribute__
(
variable_name
)
...
...
@@ -136,8 +142,37 @@ class variable_mgr():
if
__name__
==
'
__main__
'
:
from
core_tools.data.SQL.connect
import
set_up_local_storage
,
set_up_remote_storage
# set_up_local_storage('stephan', 'magicc', 'test', 'project', 'set_up', 'sample')
set_up_local_storage
(
"
xld_user
"
,
"
XLDspin001
"
,
"
vandersypen_data
"
,
"
6dot
"
,
"
XLD
"
,
"
6D3S - SQ20-20-5-18-4
"
)
set_up_local_storage
(
"
xld_user
"
,
"
XLDspin001
"
,
"
vandersypen_data
"
,
"
6dot
"
,
"
XLD
"
,
"
6D2S - SQ21-1-2-10-DEV-1
"
)
import
numpy
as
np
t
=
variable_mgr
()
print
(
t
.
vars
.
keys
())
import
os
import
matplotlib.pyplot
as
plt
try
:
os
.
mkdir
(
'
C:/users/V2/Desktop/calibration_data
'
)
except
:
pass
for
var
in
list
(
t
.
vars
.
keys
())[
2
:]:
x
,
y
=
t
.
get_history
(
var
)
plt
.
title
(
var
)
plt
.
figure
(
figsize
=
(
8
,
6
),
dpi
=
80
)
idx
=
(
x
>=
np
.
datetime64
(
'
2021-07-05T03:30
'
))
&
(
x
<=
np
.
datetime64
(
'
2021-08-25T03:30
'
))
fig
,
axs
=
plt
.
subplots
()
average
=
np
.
average
(
y
[
idx
])
std
=
np
.
std
(
y
[
idx
])
# plt.ylim((average-std*1.5,average+std*1.5))
axs
.
plot
(
x
[
idx
],
y
[
idx
])
for
label
in
axs
.
get_xticklabels
(
which
=
'
major
'
):
label
.
set
(
rotation
=
30
,
horizontalalignment
=
'
right
'
)
# plt.show()
try
:
os
.
mkdir
(
f
'
C:/users/V2/Desktop/calibration_data/
{
var
}
/
'
)
except
:
pass
np
.
savetxt
(
f
'
C:/users/V2/Desktop/calibration_data/
{
var
}
/raw.txt
'
,
np
.
array
([
x
,
y
]).
T
,
fmt
=
'
%s
'
)
np
.
save
(
f
'
C:/users/V2/Desktop/calibration_data/
{
var
}
/raw.npy
'
,
np
.
array
([
x
,
y
]).
T
)
plt
.
savefig
(
f
'
C:/users/V2/Desktop/calibration_data/
{
var
}
/_
{
var
}
.png
'
)
t
=
variable_mgr
()
...
...
This diff is collapsed.
Click to expand it.
core_tools/utility/variable_mgr/var_mgr_sql.py
+
27
−
5
View file @
2e225df0
...
...
@@ -5,6 +5,7 @@ from psycopg2.errors import UndefinedColumn
from
psycopg2
import
sql
import
datetime
,
time
import
numpy
as
np
def
to_postgres_time
(
my_date_time
):
return
time
.
strftime
(
"
%a, %d %b %Y %H:%M:%S +0000
"
,
my_date_time
.
timetuple
())
...
...
@@ -53,6 +54,26 @@ class var_sql_queries:
return
{}
return
res
[
0
]
def
get_history
(
conn
,
variable_name
):
'''
get the full history of a certain variable
Args:
variable_name (str) : name of the variable to fetch
Returns:
time, values : returns the time and associated values of the requested parameter
'''
data
=
[]
for
name
in
[
sql
.
Identifier
(
'
insert_time
'
),
sql
.
Identifier
(
variable_name
)]:
query
=
sql
.
SQL
(
"
select {0} from {1}
"
).
format
(
sql
.
SQL
(
'
,
'
).
join
([
name
]),
sql
.
SQL
(
var_sql_queries
.
gen_table_content_name
()))
query
+=
sql
.
SQL
(
"
WHERE {0} IS NOT NULL
"
).
format
(
sql
.
Identifier
(
variable_name
))
query
+=
sql
.
SQL
(
"
ORDER BY {0} {1}
"
).
format
(
sql
.
Identifier
(
'
id
'
),
sql
.
SQL
(
'
ASC
'
))
data
+=
[
np
.
array
(
execute_query
(
conn
,
query
))]
return
data
[
0
][
~
np
.
isnan
(
data
[
1
])],
data
[
1
][
~
np
.
isnan
(
data
[
1
])]
def
update_val
(
conn
,
name
,
value
):
all_vals
=
var_sql_queries
.
get_all_values
(
conn
)
if
name
is
not
None
:
...
...
@@ -93,8 +114,8 @@ class var_sql_queries:
if
__name__
==
'
__main__
'
:
from
core_tools.data.SQL.connect
import
set_up_local_storage
,
set_up_remote_storage
from
core_tools.utility.variable_mgr.var_mgr
import
variable_mgr
set_up_local_storage
(
'
stephan
'
,
'
magicc
'
,
'
test
'
,
'
project
'
,
'
set_up
'
,
'
sample
'
)
set_up_local_storage
(
"
xld_user
"
,
"
XLDspin001
"
,
"
vandersypen_data
"
,
"
6dot
"
,
"
XLD
"
,
"
SQ21-XX-X-XX-X
"
)
#
set_up_local_storage('stephan', 'magicc', 'test', 'project', 'set_up', 'sample')
set_up_local_storage
(
"
xld_user
"
,
"
XLDspin001
"
,
"
vandersypen_data
"
,
"
6dot
"
,
"
XLD
"
,
"
6D2S - SQ21-1-2-10-DEV-1
"
)
conn
=
variable_mgr
().
conn_local
var_sql_queries
.
init_table
(
conn
)
...
...
@@ -102,7 +123,8 @@ if __name__ == '__main__':
# var_sql_queries.add_variable(conn, "SD1_P_on3execute_statement(conn, statement_1)", "mV", "SD voltages", 0.1)
# var_sql_queries.add_variable(conn, "SD1_P_on", "mV", "SD voltages", 0.1)
# var_sql_queries.update_val(conn, "SD1_P_on", 12)
print
(
var_sql_queries
.
get_all_values
(
conn
))
print
(
var_sql_queries
.
get_all_specs
(
conn
))
var_sql_queries
.
remove_variable
(
conn
,
"
PHASE_q2_q6_X
"
)
# print(var_sql_queries.get_all_values(conn))
# print(var_sql_queries.get_all_specs(conn))
print
(
var_sql_queries
.
get_history
(
conn
,
'
q1_MW_power
'
))
# var_sql_queries.remove_variable(conn, "PHASE_q2_q6_X")
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