mdbq 1.0.9__tar.gz → 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {mdbq-1.0.9 → mdbq-1.1.1}/PKG-INFO +1 -1
  2. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/aggregation/mysql_types.py +1 -1
  3. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/aggregation/query_data.py +1 -0
  4. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mysql/mysql.py +33 -20
  5. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq.egg-info/PKG-INFO +1 -1
  6. {mdbq-1.0.9 → mdbq-1.1.1}/setup.py +1 -1
  7. {mdbq-1.0.9 → mdbq-1.1.1}/README.txt +0 -0
  8. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/__init__.py +0 -0
  9. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/__version__.py +0 -0
  10. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/aggregation/__init__.py +0 -0
  11. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/aggregation/aggregation.py +0 -0
  12. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/aggregation/df_types.py +0 -0
  13. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/aggregation/optimize_data.py +0 -0
  14. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/bdup/__init__.py +0 -0
  15. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/bdup/bdup.py +0 -0
  16. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/clean/__init__.py +0 -0
  17. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/clean/data_clean.py +0 -0
  18. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/company/__init__.py +0 -0
  19. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/company/copysh.py +0 -0
  20. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/config/__init__.py +0 -0
  21. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/config/get_myconf.py +0 -0
  22. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/config/products.py +0 -0
  23. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/config/set_support.py +0 -0
  24. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/config/update_conf.py +0 -0
  25. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/dataframe/__init__.py +0 -0
  26. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/dataframe/converter.py +0 -0
  27. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/log/__init__.py +0 -0
  28. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/log/mylogger.py +0 -0
  29. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mongo/__init__.py +0 -0
  30. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mongo/mongo.py +0 -0
  31. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mysql/__init__.py +0 -0
  32. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mysql/data_types_/345/215/263/345/260/206/345/210/240/351/231/244.py" +0 -0
  33. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mysql/s_query.py +0 -0
  34. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/mysql/year_month_day.py +0 -0
  35. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/other/__init__.py +0 -0
  36. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/other/porxy.py +0 -0
  37. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/other/pov_city.py +0 -0
  38. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/other/ua_sj.py +0 -0
  39. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/pbix/__init__.py +0 -0
  40. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/pbix/pbix_refresh.py +0 -0
  41. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/pbix/refresh_all.py +0 -0
  42. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq/spider/__init__.py +0 -0
  43. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq.egg-info/SOURCES.txt +0 -0
  44. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq.egg-info/dependency_links.txt +0 -0
  45. {mdbq-1.0.9 → mdbq-1.1.1}/mdbq.egg-info/top_level.txt +0 -0
  46. {mdbq-1.0.9 → mdbq-1.1.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mdbq
3
- Version: 1.0.9
3
+ Version: 1.1.1
4
4
  Home-page: https://pypi.org/project/mdbsql
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -155,7 +155,7 @@ def mysql_all_dtypes(db_name=None, table_name=None, path=None):
155
155
  if not path:
156
156
  path = set_support.SetSupport(dirname='support').dirname
157
157
 
158
- username, password, host, port = get_myconf.select_config_values(target_service='company', database='mysql')
158
+ username, password, host, port = get_myconf.select_config_values(target_service='home_lx', database='mysql')
159
159
  config = {
160
160
  'host': host,
161
161
  'port': port,
@@ -373,6 +373,7 @@ class GroupBy:
373
373
  print(f'<{table_name}>: Groupby 类尚未配置,数据为空')
374
374
  return pd.DataFrame({})
375
375
 
376
+ @try_except
376
377
  def performance(self, bb_tg=True):
377
378
  # print(self.data_tgyj)
378
379
  tg, syj, idbm, pic, cost = (
@@ -131,21 +131,24 @@ class MysqlUpload:
131
131
  print(f'{now}正在更新 mysql ({self.host}:{self.port}) {db_name}/{table_name}')
132
132
  datas = df.to_dict(orient='records')
133
133
  for data in datas:
134
- cols = ', '.join(f"`{item}`" for item in data.keys()) # 列名转义
135
- # data.update({item: f"{data[item]}" for item in data.keys()}) # 全部值转字符, 不是必须的
136
- values = ', '.join([f"'{item}'" for item in data.values()]) # 值要加单引号 ''
137
- condition = []
138
- for k, v in data.items():
139
- condition += [f"`{k}` = '{v}'"]
140
- condition = ' AND '.join(condition) # 构建查询条件
141
- # print(condition)
142
-
143
- sql = f"SELECT {cols} FROM `{table_name}` WHERE {condition}"
144
- cursor.execute(sql)
145
- result = cursor.fetchall() # 获取查询结果, 如果有结果返回 list,没有则返回空元组 tuple
146
- if not result: # 数据不存在则插入
147
- sql = f"INSERT INTO `{table_name}` ({cols}) VALUES ({values});"
134
+ try:
135
+ cols = ', '.join(f"`{item}`" for item in data.keys()) # 列名转义
136
+ # data.update({item: f"{data[item]}" for item in data.keys()}) # 全部值转字符, 不是必须的
137
+ values = ', '.join([f"'{item}'" for item in data.values()]) # 值要加单引号 ''
138
+ condition = []
139
+ for k, v in data.items():
140
+ condition += [f"`{k}` = '{v}'"]
141
+ condition = ' AND '.join(condition) # 构建查询条件
142
+ # print(condition)
143
+
144
+ sql = f"SELECT {cols} FROM `{table_name}` WHERE {condition}"
148
145
  cursor.execute(sql)
146
+ result = cursor.fetchall() # 获取查询结果, 如果有结果返回 list,没有则返回空元组 tuple
147
+ if not result: # 数据不存在则插入
148
+ sql = f"INSERT INTO `{table_name}` ({cols}) VALUES ({values});"
149
+ cursor.execute(sql)
150
+ except Exception as e:
151
+ print(f'mysql -> df_to_mysql 报错: {e}')
149
152
  connection.commit() # 提交事务
150
153
 
151
154
  def convert_dtypes(self, df, db_name, table_name):
@@ -180,6 +183,18 @@ class MysqlUpload:
180
183
 
181
184
  def convert_dtype_to_sql(self, df, col, dtype):
182
185
  """ 按照以下规则转换DataFrame列的数据类型为 MYSQL 专有的数据类型 """
186
+
187
+ def find_longest_decimal_value(number_list):
188
+ # 取列表中小数位数最长的值
189
+ longest_value = None
190
+ max_decimals = 0
191
+ for num in number_list:
192
+ decimal_places = len(str(num).split('.')[1])
193
+ if decimal_places > max_decimals:
194
+ max_decimals = decimal_places
195
+ longest_value = num
196
+ return longest_value
197
+
183
198
  # 最优先处理 ID 类型, 在 mysql 里面, 有些列数字过长不能存储为 int 类型
184
199
  if 'id' in col or 'ID' in col or 'Id' in col or '摘要' in col or '商家编码' in col or '单号' in col or '款号' in col:
185
200
  return 'mediumtext'
@@ -204,9 +219,9 @@ class MysqlUpload:
204
219
  return 'mediumtext'
205
220
  return 'INT'
206
221
  elif dtype == 'float64':
207
- # step = len(str(max(df[col].tolist()))) # 数字长度包含小数点
208
- int_step = len(str(max(df[col].tolist())).split('.')[0]) # 整数位数长度
209
- f_step = len(str(max(df[col].tolist())).split('.')[1]) # 小数位数长度
222
+ res = find_longest_decimal_value(df[col].tolist()) # 取小数位数最长的值
223
+ int_step = len(str(res).split('.')[0]) # 整数位数长度
224
+ f_step = len(str(res).split('.')[1]) # 小数位数长度
210
225
  if int_step >= 12:
211
226
  return 'mediumtext' # mysql 中不要使用 float 和 double 类型,会影响计算结果
212
227
  elif int_step >= 8 and f_step >= 0:
@@ -686,7 +701,7 @@ if __name__ == '__main__':
686
701
  username, password, host, port = get_myconf.select_config_values(target_service='company', database='mysql')
687
702
  print(username, password, host, port)
688
703
 
689
- file = '/Users/xigua/Downloads/余额查询.csv'
704
+ file = '/Users/xigua/数据中心/原始文件2/京东报表/JD商品明细spu/2024-08/spu_2024-08-18_全部渠道_商品明细.csv'
690
705
  one_file_to_mysql(
691
706
  file=file,
692
707
  db_name='test',
@@ -695,5 +710,3 @@ if __name__ == '__main__':
695
710
  database='mysql'
696
711
  )
697
712
 
698
-
699
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mdbq
3
- Version: 1.0.9
3
+ Version: 1.1.1
4
4
  Home-page: https://pypi.org/project/mdbsql
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -3,7 +3,7 @@
3
3
  from setuptools import setup, find_packages
4
4
 
5
5
  setup(name='mdbq',
6
- version='1.0.9',
6
+ version='1.1.1',
7
7
  author='xigua, ',
8
8
  author_email="2587125111@qq.com",
9
9
  url='https://pypi.org/project/mdbsql',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes