49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
"""专题图例导出。"""
|
|
import csv
|
|
from . import config
|
|
|
|
|
|
def write_excellent_heatmap_legend(output_dir, field):
|
|
legend_path = output_dir / "excellent_heatmap_legend.csv"
|
|
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
|
|
writer = csv.writer(file)
|
|
writer.writerow(["field", "rank_range", "red", "green", "blue", "alpha", "meaning"])
|
|
rank_ranges = ("top_10_percent", "10_to_40_percent", "40_to_70_percent", "bottom_30_percent")
|
|
for rank_range, color in zip(rank_ranges, config.EXCELLENT_COLORS):
|
|
writer.writerow([field, rank_range, *color, config.HEATMAP_ALPHA, "ranked-pixel distribution"])
|
|
writer.writerow([field, "nodata", 0, 0, 0, 0, "transparent no data"])
|
|
return legend_path
|
|
|
|
|
|
def write_competitor_signal_legend(output_dir):
|
|
legend_path = output_dir / "competitor_signal_legend.csv"
|
|
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
|
|
writer = csv.writer(file)
|
|
writer.writerow(["field", "rule_or_rsrp_range", "red", "green", "blue", "alpha", "filter"])
|
|
competitor_filter = (
|
|
f"{config.MOBILE_WEAK_COVER_FIELD}/{config.MOBILE_TOTAL_FIELD} < {config.COMPETITOR_SIGNAL_MOBILE_WEAK_RATIO_MAX}%"
|
|
f" and ({config.EXCELLENT_CELL_FIELD} = 0"
|
|
f" or {config.WEAK_COVER_FIELD}/{config.EXCELLENT_CELL_FIELD} > {config.COMPETITOR_SIGNAL_WEAK_RATIO_MIN}%)"
|
|
)
|
|
writer.writerow([
|
|
config.EXCELLENT_CELL_FIELD,
|
|
"= 0",
|
|
*config.COMPETITOR_SIGNAL_RSRP_COLORS[0],
|
|
config.HEATMAP_ALPHA,
|
|
competitor_filter,
|
|
])
|
|
ranges = (
|
|
"< -110",
|
|
"[-110, -104)",
|
|
"[-104, -98)",
|
|
"[-98, -92)",
|
|
"[-92, -86)",
|
|
"[-86, -80)",
|
|
"[-80, -74)",
|
|
"[-74, 0]",
|
|
)
|
|
for value_range, color in zip(ranges, config.COMPETITOR_SIGNAL_RSRP_COLORS):
|
|
writer.writerow([config.RSRP_FIELD, value_range, *color, config.HEATMAP_ALPHA, competitor_filter])
|
|
writer.writerow([config.RSRP_FIELD, "not_eligible_or_invalid", 0, 0, 0, 0, competitor_filter])
|
|
return legend_path
|