egm/parameter_test.py

76 lines
3.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import datetime
import pymongo
from easyprocess import EasyProcess
import numpy as np
import re
if __name__ == "__main__":
result = {}
utc_now = datetime.datetime.utcnow()
print(f"当前utc时间{utc_now}")
client = pymongo.MongoClient(
"mongodb+srv://dmy:uqXLtjkJRKzWYnSpK8jF@cluster0.x0ged.mongodb.net/db?retryWrites=true&w=majority"
)
db = client["db"]
result_collection = db["result_collection"]
with open("article_parameter.toml", encoding="utf-8") as toml_file:
toml_string = toml_file.read()
for altitude in np.arange(1500, 4000, 500):
for height in np.arange(100, 160, 10):
for ground_arm_length in np.arange(17, 25, 0.01):
replaced_toml_string = toml_string
replaced_toml_string = replaced_toml_string.replace(
"ARM", f"{ground_arm_length:.3f}"
)
replaced_toml_string = replaced_toml_string.replace(
"HEIGHT", str(height)
)
replaced_toml_string = replaced_toml_string.replace(
"MID", str(height - 20)
)
replaced_toml_string = replaced_toml_string.replace(
"ALTITUDE", str(altitude)
)
with open(
"abc_parameter.toml", "w", encoding="utf-8"
) as parameter_toml_file:
parameter_toml_file.write(replaced_toml_string)
print(f"计算{altitude}m海拔{height}m全塔高,{ground_arm_length:.3f}m横担长的跳闸率")
console_output = (
EasyProcess(
[
"python",
"d:/code/EGM/main.py",
"d:/code/EGM/abc_parameter.toml",
]
)
.call()
.stderr
)
tripout_rate = re.findall("不同相跳闸率是\[(.*)\]", console_output)[0]
print(f"跳闸率是{tripout_rate}")
if float(tripout_rate) < 0.14:
print(f"最短地线横担是{ground_arm_length:.3f}m")
if altitude not in result:
result[altitude] = {}
if height not in result[altitude]:
result[altitude][height] = {}
result[altitude][height] = ground_arm_length
record_id = result_collection.insert_one(
{
"cate": "最短地线横担长度",
"utc_time": utc_now,
"altitude": float(altitude),
"height": float(height),
"地线横担长度": float(ground_arm_length),
"跳闸率": tripout_rate,
}
)
print(f"id{record_id}")
break
for altitude in np.arange(1500, 4000, 500):
for height in np.arange(100, 160, 10):
ground_arm_length = result[altitude][height]
print(f"{altitude}m海拔{height}m全塔高,需要最短{ground_arm_length:.3f}m横担")