Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-hwinfo-daemon
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
Container 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
MeanSpec (SCE338 2024-2 Group 1)
meanspec-hwinfo-daemon
Commits
8ac006fc
Verified
Commit
8ac006fc
authored
6 months ago
by
Eunhak Lee
Browse files
Options
Downloads
Patches
Plain Diff
fix: 새로운 부품을 만들 때 잘못된 테이블의 컬럼을 참조하는 문제
parent
51611018
No related branches found
No related tags found
No related merge requests found
Pipeline
#10616
passed
6 months ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
push_to_db.py
+22
-31
22 additions, 31 deletions
push_to_db.py
with
22 additions
and
31 deletions
push_to_db.py
+
22
−
31
View file @
8ac006fc
...
...
@@ -5,23 +5,20 @@ import os
import
re
import
sys
import
time
import
parse
import
redis
import
psycopg2
import
traceback
from
datetime
import
datetime
,
timedelta
import
parse
import
utils
def
conn
():
return
psycopg2
.
connect
(
host
=
"
hub.enak.kr
"
,
user
=
"
meanspec
"
,
password
=
"
foopassword123
"
,
dbname
=
"
meanspec
"
)
from
datetime
import
datetime
,
timedelta
def
check_similarity
(
_conn
,
name
,
part_type
):
_cursor
=
_conn
.
cursor
()
where_clause
=
"
WHERE type =
'
{}
'"
.
format
(
part_type
.
upper
())
if
part_type
else
""
_auto_threshold
=
1.0
if
part_type
==
'
RAM
'
else
0.13
_auto_threshold
=
1.0
if
part_type
in
(
'
RAM
'
,
'
SSD
'
,
'
HDD
'
,)
else
0.13
_cursor
.
execute
(
"
WITH comp AS (SELECT id, name, similarity(name::text, %s::text) as sim FROM parts
"
+
where_clause
+
"
) SELECT * FROM comp WHERE sim >=%s ORDER BY sim DESC LIMIT 5;
"
,
(
name
,
_auto_threshold
,))
...
...
@@ -65,7 +62,7 @@ def create_new_one(_dict, part_type, _cursor):
values
=
[
value
for
_
,
value
in
_obj
]
sql
=
"""
WITH rows AS (INSERT INTO parts (name, type) VALUES (%s, %s) RETURNING id)
INSERT INTO part_info_{type} (part_id, {columns}) (SELECT rows.id, {value_entries} FROM rows) RETURNING
rows.
id;
"""
.
format
(
type
=
_part_type_enum
,
columns
=
columns
,
value_entries
=
"
,
"
.
join
([
"
%s
"
]
*
len
(
values
)))
INSERT INTO part_info_{type} (part_id, {columns}) (SELECT rows.id, {value_entries} FROM rows) RETURNING
part_
id;
"""
.
format
(
type
=
_part_type_enum
,
columns
=
columns
,
value_entries
=
"
,
"
.
join
([
"
%s
"
]
*
len
(
values
)))
_cursor
.
execute
(
sql
,
(
name
,
_part_type_enum
,
*
values
))
data
=
_cursor
.
fetchall
()
...
...
@@ -145,6 +142,10 @@ def func():
_user_id
=
R
.
get
(
f
"
mypc:code:
{
code
}
:user_id
"
)
_transaction_id
=
R
.
get
(
f
"
mypc:code:
{
code
}
:transaction_id
"
)
_xml_document
=
R
.
get
(
f
"
mypc:code:
{
code
}
:document
"
)
print
(
"
(User ID (raw):
"
,
_user_id
)
print
(
"
Transaction ID: (raw)
"
,
_transaction_id
)
print
(
"
XML starts with (raw):
"
,
_xml_document
)
assert
_user_id
is
not
None
,
"
userId must not be null
"
assert
_transaction_id
is
not
None
,
"
transactionId must not be null
"
assert
_xml_document
is
not
None
,
"
document must not be null
"
...
...
@@ -163,10 +164,16 @@ def func():
print
(
"
Matching parts
"
)
for
part_type
,
parts
in
_parts
.
items
():
# 부품 유형별 iterate
for
part
in
parts
:
# 부품별 iterat
if
part_type
==
"
DISK
"
:
disk_part_type
=
part
.
pop
(
"
type
"
,
"
not_set
"
).
upper
()
if
disk_part_type
not
in
(
"
SSD
"
,
"
HDD
"
,):
print
(
"
[WARNING] not supported disk type
"
,
disk_part_type
,
file
=
sys
.
stderr
)
continue
for
part
in
parts
:
# 부품별 iterate
part_type
=
disk_part_type
_matched_id
=
match_part_obj_into_db
(
part
,
part_type
)
if
not
_matched_id
:
# DB에 없는 부품이라면
...
...
@@ -203,30 +210,14 @@ def func():
if
__name__
==
"
__main__
"
:
_first_run
=
True
_redis_url
=
os
.
getenv
(
"
REDIS_URL
"
,
"
redis://localhost:6379/
"
)
print
(
"
Connecting Redis to
"
,
_redis_url
)
global
R
R
=
redis
.
Redis
.
from_url
(
_redis_url
)
try
:
_
=
R
.
keys
()
print
(
"
Successfully connected Redis.
"
)
except
:
print
(
"
Failed to connect Redis.
"
,
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
R
=
utils
.
env_connect_redis
()
if
not
R
:
exit
(
1
)
_db_host
=
os
.
getenv
(
"
DB_HOST
"
,
"
localhost
"
)
_db_port
=
int
(
os
.
getenv
(
"
DB_PORT
"
,
"
5432
"
))
_db_name
=
os
.
getenv
(
"
DB_NAME
"
,
"
meanspec
"
)
_db_user
=
os
.
getenv
(
"
DB_USER
"
,
"
meanspec
"
)
_db_pass
=
os
.
getenv
(
"
DB_PASS
"
,
"
foopassword123
"
)
print
(
"
Connecting PostgreSQL to
"
,
_db_host
,
_db_port
,
_db_name
,
_db_user
)
global
db_conn
try
:
db_conn
=
psycopg2
.
connect
(
host
=
_db_host
,
port
=
_db_port
,
dbname
=
_db_name
,
user
=
_db_user
,
password
=
_db_pass
)
except
:
print
(
"
Failed to connect PostgreSQL.
"
,
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
db_conn
=
utils
.
env_connect_postgresql
()
if
not
db_conn
:
exit
(
1
)
_next_run_delta
=
timedelta
(
seconds
=
int
(
os
.
getenv
(
"
PARSE_DAEMON_REFRESH_INTERVAL
"
,
5
)))
...
...
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