tianyun 2 éve
szülő
commit
d2aac72e4a
2 módosított fájl, 42 hozzáadás és 7 törlés
  1. 32 0
      project/compress_dir_img.py
  2. 10 7
      tmp2.py

+ 32 - 0
project/compress_dir_img.py

@@ -0,0 +1,32 @@
+import os
+from PIL import Image
+import argparse
+
+
+def convert_to_webp(dir_path):
+    for subdir, dirs, files in os.walk(dir_path):
+        for file in files:
+            filepath = subdir + os.sep + file
+            if filepath.endswith(".webp"):
+                continue
+            try:
+                img = Image.open(filepath)
+                if img.format == "WEBP":
+                    continue
+                webp_path = filepath + ".webp"
+                img.save(webp_path, "WEBP")
+                os.remove(filepath)
+                os.rename(webp_path, filepath)
+            except IOError:
+                print(f"Cannot convert {file}")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description='Convert images to webp format.')
+    parser.add_argument('dir_path', type=str, help='Directory path to scan for images')
+
+    args = parser.parse_args()
+
+    convert_to_webp(args.dir_path)
+
+# python compress_dir_img.py /path/to/directory

+ 10 - 7
tmp2.py

@@ -1,8 +1,11 @@
-import math
+def exec(obj):
+    import json
+    all_key = ['zScore', 'yingyunzijinZhouzhuancishu', 'aeM6IdOrgnumD', 'area', 'bh10017', 'bh10018', 'bh10022', 'bhScore', 'cnGudongChange6m', 'cnHigh', 'cnZeroincome24m', 'credit15', 'creditcardScoreV4', 'cunhuoZhouzhuanratio', 'cvVatSales12m', 'drsNodebtscore', 'fraud18', 'gudingzichanZongzichanRatio', 'hades1', 'highMostCnRuleType', 'incomeTaxReal12m', 'largeAmountPaymentV4', 'lirunRatio', 'liudongRatio', 'liudongzichanZhouzhuanratio', 'maxRiskLevel', 'registcapi', 'riskDegree', 'riskScore', 'slopeVatSales12m', 'stockpercent', 'stockpercentJicha', 'sudongRatio', 'tlIdM6NbankPassorg', 'vatMonth12m', 'vatSales3mRatio', 'vatSalesHuanbi6m', 'yingfuZhouzhuanratio', 'yingshouZhouzhuanratio']
+    # 创建一个对象,里面有all_key对应的key,假如这个key在obj里面,则赋值为obj里的value,假如没有则赋值为null
+    data_obj = {key: obj[key] if key in obj else None for key in all_key}
+    # 然后把对象json化赋值到下面的obj的data属性里面
+    obj['data'] = json.dumps(data_obj)
+    return obj
 
-x = 1
-param = {
-    'large_amount_payment_v4': 6
-}
-a = 590 - 200 * math.log2((1 / (1 + math.exp(1.99530393989402 - 7.7 * x - 0.02 * param['large_amount_payment_v4']))) / ((1 - (1 / (1 + math.exp(1.99530393989402 - 7.7 * x - 0.02 * param['large_amount_payment_v4'])))) * 0.1936))
-print(a)
+
+print(exec({"zScore": 1}))