Skip to content

Commit

Permalink
fix apibm db.py str, (#2140)
Browse files Browse the repository at this point in the history
* add api benchmark runner_ci.py

* add api benchmark runner_ci.py, test=model

* add api benchmark runner_ci.py 2, test=model

* add op_correctness_and_stability_phase_one.yml, test=model

* add lite demo to moduletrans, test=model

* add api benchmark new db.py, test=model

* fix apibm db.py str, test=model
  • Loading branch information
Zeref996 authored Apr 13, 2023
1 parent b82d40e commit 558152a
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions framework/e2e/api_benchmark/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
db object
"""

import os
import socket
import platform
from datetime import datetime
import json
import yaml
import paddle
import pymysql

# from utils.logger import logger
Expand Down Expand Up @@ -52,11 +47,11 @@ def insert(self, table, data):
id = -1
table = table
ls = [(k, data[k]) for k in data if data[k] is not None]
keys = ",".join(i[0] for i in ls)
keys = ",".join(("`" + i[0] + "`") for i in ls)
values = ",".join("%r" % i[1] for i in ls)

sql = "INSERT INTO {table}({keys}) VALUES ({values})".format(table=table, keys=keys, values=values)
# sql = 'insert %s (' % table + ','.join(i[0] for i in ls) + \
# sql = 'insert %s (' % table + ','.join(('`' + i[0] + '`') for i in ls) + \
# ') values (' + ','.join('%r' % i[1] for i in ls) + ')'
try:
self.cursor.execute(sql)
Expand All @@ -71,9 +66,9 @@ def update(self, table, data, data_condition):
table = table
sql = (
"UPDATE %s SET " % table
+ ",".join("%s=%r" % (k, data[k]) for k in data)
+ ",".join("%s=%r" % (("`" + k + "`"), data[k]) for k in data)
+ " WHERE "
+ " AND ".join("%s=%r" % (k, data_condition[k]) for k in data_condition)
+ " AND ".join("%s=%r" % (("`" + k + "`"), data_condition[k]) for k in data_condition)
)

try:
Expand All @@ -87,7 +82,7 @@ def update_by_id(self, table, data, id):
table = table
sql = (
"UPDATE %s SET " % table
+ ",".join("%s=%r" % (k, data[k]) for k in data)
+ ",".join("%s=%r" % (("`" + k + "`"), data[k]) for k in data)
+ " WHERE "
+ "%s=%r" % ("`id`", id)
)
Expand Down Expand Up @@ -130,31 +125,31 @@ def select_by_id(self, table, id):

# table = 'job'
# data = {
# '`framework`': 'paddle', '`commit`': 'aaabbbccc',
# '`system`': 'Darwin', '`cuda`': '1121', '`cudnn`': '2233',
# '`update_time`': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 'framework': 'paddle', 'commit': 'aaabbbccc',
# 'system': 'Darwin', 'cuda': '1121', 'cudnn': '2233',
# 'update_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# }
# id = db.insert(table='job', data=data)
# print('id is: ', id)

# table = 'job'
# data = {
# '`framework`': 'paddle11', '`commit`': '132aaabbbccc',
# '`system`': 'Darwin', '`cuda`': '1121', '`cudnn`': '2233',
# '`update_time`': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 'framework': 'paddle11', 'commit': '132aaabbbccc',
# 'system': 'Darwin', 'cuda': '1121', 'cudnn': '2233',
# 'update_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# }
# data_condition = {
# '`id`': '58'
# 'id': '60'
# }
# db.update(table='job', data=data, data_condition=data_condition)

# table = 'job'
# data = {
# '`framework`': 'paddle11', '`commit`': '132aaabbbccc',
# '`system`': 'Darwin', '`cuda`': '1121', '`cudnn`': '2233',
# '`update_time`': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 'framework': 'paddle22', 'commit': '33323aaabbbccc',
# 'system': 'Darwin', 'cuda': '1121', 'cudnn': '2233',
# 'update_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# }
# id = 59
# id = 60
# db.update_by_id(table='job', data=data, id=id)

# table = 'job'
Expand Down

0 comments on commit 558152a

Please sign in to comment.