refactor codes and names

This commit is contained in:
hsafaei
2026-02-12 11:19:58 +03:30
parent 56084b0c8e
commit 9c99d816db
25 changed files with 395 additions and 2360 deletions
-349
View File
@@ -1,349 +0,0 @@
type_count = [
{
"key": "جلسه علمی",
"doc_count": 7332
},
{
"key": "منبر",
"doc_count": 3970
},
{
"key": "درس خارج",
"doc_count": 2450
},
{
"key": "تدریس",
"doc_count": 1401
},
{
"key": "سخنرانی",
"doc_count": 1221
},
{
"key": "-",
"doc_count": 992
},
{
"key": "مشاوره",
"doc_count": 858
},
{
"key": "مدیریت",
"doc_count": 652
},
{
"key": "مصاحبه",
"doc_count": 628
},
{
"key": "مباحثه و گفتگو",
"doc_count": 587
},
{
"key": "جزوه",
"doc_count": 583
},
{
"key": "مناظره و گفتگو",
"doc_count": 496
},
{
"key": "گزارش",
"doc_count": 395
},
{
"key": "--",
"doc_count": 250
},
{
"key": "جدول",
"doc_count": 208
},
{
"key": "کتاب",
"doc_count": 173
},
{
"key": "صورت جلسه",
"doc_count": 126
},
{
"key": "فهرست",
"doc_count": 124
},
{
"key": "ارائه",
"doc_count": 90
},
{
"key": "بازدید (دیدار)",
"doc_count": 83
},
{
"key": "مقاله",
"doc_count": 81
},
{
"key": "طرح",
"doc_count": 74
},
{
"key": "کلیپ",
"doc_count": 68
},
{
"key": "گزارش رصد",
"doc_count": 64
},
{
"key": "نامه",
"doc_count": 48
},
{
"key": "نمودار",
"doc_count": 45
},
{
"key": "آیین نامه",
"doc_count": 36
},
{
"key": "تقریر",
"doc_count": 35
},
{
"key": "خلاصه",
"doc_count": 25
},
{
"key": "پیش نویس",
"doc_count": 25
},
{
"key": "نقد",
"doc_count": 23
},
{
"key": "چکیده",
"doc_count": 16
},
{
"key": "یادبود",
"doc_count": 13
},
{
"key": "فرم",
"doc_count": 12
},
{
"key": "فرم فیش",
"doc_count": 11
},
{
"key": "مناجات",
"doc_count": 10
},
{
"key": "دعا و مناجات",
"doc_count": 8
},
{
"key": "فیش",
"doc_count": 6
},
{
"key": "پرسش و پاسخ",
"doc_count": 6
},
{
"key": "بیانیه",
"doc_count": 5
},
{
"key": "اجلاسیه",
"doc_count": 4
},
{
"key": "پایان نامه",
"doc_count": 4
},
{
"key": "",
"doc_count": 3
},
{
"key": "آئین نامه",
"doc_count": 3
},
{
"key": "رزومه",
"doc_count": 3
},
{
"key": "قرارداد",
"doc_count": 3
},
{
"key": "مصوبه",
"doc_count": 3
},
{
"key": "نمونه سوال",
"doc_count": 3
},
{
"key": "همایش",
"doc_count": 3
},
{
"key": "پژوهش",
"doc_count": 3
},
{
"key": "چارت",
"doc_count": 3
},
{
"key": "کنفرانس",
"doc_count": 3
},
{
"key": "تلخیص",
"doc_count": 2
},
{
"key": "قرائت زیارت",
"doc_count": 2
},
{
"key": "لیست",
"doc_count": 2
},{
"key": "متن جلسه",
"doc_count": 2
},
{
"key": "مستند تلوزیونی",
"doc_count": 2
},
{
"key": "نشست علمی",
"doc_count": 2
},
{
"key": "کتاب داخلی",
"doc_count": 2
},
{
"key": "گزارش جلسه",
"doc_count": 2
},
{
"key": "برنامه",
"doc_count": 1
},
{
"key": "بروشور",
"doc_count": 1
},
{
"key": "بزرگداشت",
"doc_count": 1
},
{
"key": "جزو",
"doc_count": 1
},
{
"key": "خطبه عقد(دائم)",
"doc_count": 1
},
{
"key": "روضه",
"doc_count": 1
},
{
"key": "زندگی نامه",
"doc_count": 1
},
{
"key": "زیارتنامه",
"doc_count": 1
},
{
"key": "سائر",
"doc_count": 1
},
{
"key": "سالگرد",
"doc_count": 1
},
{
"key": "سایر",
"doc_count": 1
},
{
"key": "طرج",
"doc_count": 1
},
{
"key": "عقد",
"doc_count": 1
},
{
"key": "ماتریس",
"doc_count": 1
},
{
"key": "مدل",
"doc_count": 1
},
{
"key": "مراحل دستیابی و به کارگیری الگوی پیشرفت اسلامی ـ ",
"doc_count": 1
},
{
"key": "مقالات",
"doc_count": 1
},
{
"key": "مقاله و ارائه",
"doc_count": 1
},
{
"key": "نماه",
"doc_count": 1
},
{
"key": "نمایه",
"doc_count": 1
},
{
"key": "هرم",
"doc_count": 1
},
{
"key": "پرسشنامه",
"doc_count": 1
},
{
"key": "پروژه",
"doc_count": 1
},
{
"key": "پیش نشست",
"doc_count": 1
},
{
"key": "کاربرگ",
"doc_count": 1
},
{
"key": "کتاب سایت",
"doc_count": 1
},
{
"key": "کمیسیون خبرگان",
"doc_count": 1
}
]
-160
View File
@@ -1,160 +0,0 @@
import traceback, os, orjson
import pandas as pd
from pathlib import Path
from dataParsers.app.common.elastic_helper import ElasticHelper
from dotenv import load_dotenv
def load_orjson(path: str | Path):
path = Path(path)
with path.open("rb") as f: # باید باینری باز بشه برای orjson
return orjson.loads(f.read())
def save_orjson(path, data):
with open(path, "wb") as f:
f.write(
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
)
def extract_excel_fields(file_path: str, fields: list = [], sheet_name: str = None):
"""
فایل اکسل را باز کرده و فقط فیلدهای خواسته‌شده را به‌صورت لیست از دیکشنری‌ها برمی‌گرداند.
:param file_path: مسیر فایل اکسل (.xlsx یا .xls)
:param fields: لیست نام ستون‌هایی که باید خوانده شوند
:return: لیستی از دیکشنری‌ها شامل داده‌های ستون‌های انتخاب‌شده
"""
try:
# خواندن فایل
df = pd.read_excel(file_path, sheet_name=sheet_name)
df.columns = df.columns.map(str)
if len(fields) > 0:
missing = [f for f in fields if f not in df.columns]
if missing:
print(f"⚠️ This columns mot found in file {missing}")
# for i in df.columns:
# print(f'-field ->{i}<-')
df = df[[f for f in fields if f in df.columns]]
# تبدیل به لیست از دیکشنری‌ها
data = df.to_dict(orient="records")
return data
except Exception as e:
print(f"❌ خطا در خواندن فایل اکسل: {e}")
return []
def save_excel(file_path: str, data: list):
"""ذخیره‌ی داده‌ها در فایل اکسل جدید"""
try:
df = pd.DataFrame(data)
df.to_excel(file_path, index=False)
print(f"✅ فایل با موفقیت ذخیره شد: {file_path}")
except Exception as e:
print(f"❌ خطا در ذخیره فایل اکسل: {e}")
def convert_data(item):
_id = "gnp" + str(item["id"])
tree_label = item["person_title"]
title = item["title"]
papa_id = item["papa_id"]
if papa_id == 0:
parent_id = str(0)
else:
parent_id = "gnp" + str(papa_id)
child_order = item["order"]
return {
"id": _id, # "gnt01741"
"version_key": "base_1",
"tree_key": "tree1",
"tree_label": tree_label, # "فهرست موضوعات مسائل و پاسخها",
"main_type": "tree",
"title": title, # "پیامدهای روبنایی",
"parent_id": parent_id,
"child_order": child_order,
"tags": [],
"meta_info": {},
}
load_dotenv()
es_pass = os.getenv("ES_PASSWORD")
es_url = os.getenv("ES_URL")
es_user = os.getenv("ES_USER_NAME")
es_index_name = os.getenv("GNP_TREE_INDEX_NAME")
es_helper = ElasticHelper(es_pass=es_pass, es_url=es_url, es_user=es_user)
if __name__ == "__main__":
file_path = r"D:\init_mahdi\dataParsers\041106_لیست تمام موضوعات.xlsx"
data_excel = extract_excel_fields(file_path, sheet_name="Sheet1")
print(f'data_excel {len(data_excel)}')
try:
f_data = []
for i in data_excel:
f_data.append(convert_data(i))
except Exception as e:
print(
f"*************",
)
traceback.print_exc()
print(f'f_data {len(f_data)}')
output_path = r"D:\init_mahdi\dataParsers\041106_لیست تمام موضوعات.json"
save_orjson(path=output_path, data=f_data)
bulk_data=[]
index_name_o = es_index_name
elastic = es_helper
total_count = 0
data_list = f_data
i = 0
for data in data_list :
eid = data["id"]
i = i + 1
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print('=' * 10, 'to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
bulk_data.append(
{
'_id' : eid,
'_source' : data
}
)
if len(bulk_data) > 0:
total_count += len(bulk_data)
print('=' * 10, ' to_elastic , total='+str(total_count) )
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
print("end success import_to_elastic")
# for i in f_data:
# es_res = es_helper.update_index_doc(
# is_update_state=False,
# index_name_o=es_index_name,
# eid=i["id"],
# data=i,
# )
# python -m dataParsers.app.monir.gnp_tree
+544
View File
@@ -0,0 +1,544 @@
import mariadb
from dotenv import load_dotenv
import os
import datetime
import json
import uuid
import pandas as pd
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
from app.common.elastic_helper import ElasticHelper
from app.common.general_functions import *
from app.common.text_normalizer import TextNormalizer
from app.monir.monir_options import (
get_public_options,
get_monir_options
)
load_dotenv(dotenv_path="config.env")
host = os.getenv("HOST_60")
password = os.getenv("HOST_60_PASS")
# host = os.getenv("HOST_133")
# password = os.getenv("HOST_133_PASS")
# print(host)
# print(password)
path_base_map = (
"G:\Project2\gateaway_py\elastic_backend/elastic_backend/app/schemas/mappings/"
)
# path_base_map = (
# "G:\Project2\tavasi_60\src\repo\_other/"
# )
elastic = ElasticHelper(host, password, "elastic", path_base_map)
text_normalize = TextNormalizer()
def import_simple_list_to_elastic(
elastic,
items,
prefix_id,
tree_label,
tree_key,
group_key="",
index_name_o="gn_tree",
):
bulk_data = []
total_count = 0
t1 = datetime.datetime.now()
print(t1)
i = 0
for item in items:
# print(i)
i = i + 1
row = cursor.fetchone()
if not item:
break
id = prefix_id + str(i).zfill(5)
# eid = uuid.uuid4().hex[:8]
eid = id
title = item.strip()
title = text_normalize.normalize_qanon(title)
parent_id = "0"
child_order = i
data = {
"id": eid,
"version_key": "base_1",
"tree_key": tree_key,
"tree_label": tree_label,
"main_type": "list",
"group_key": group_key,
"title": title,
"parent_id": parent_id,
"child_order": child_order,
}
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print(
"=" * 10,
"to_elastic , total=" + str(total_count),
str(i) + ", id=" + eid,
)
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
bulk_data.append({"_id": eid, "_source": data})
if len(bulk_data) > 0:
total_count += len(bulk_data)
print("=" * 10, " to_elastic , total=" + str(total_count))
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
print("end success import_to_elastic")
t2 = datetime.datetime.now()
print(t2 - t1)
def import_project_to_elastic(
cursor, elastic, project_id, project_title, index_name_o="gn_tree"
):
query = f"""
SELECT id, title, parent, child_order, meta, tags from tlist.tl_subjects
where project_id={project_id}
ORDER BY parent, child_order
"""
# print('-'*10)
# print(query)
# print('-'*10)
cursor.execute(query)
parent_nodes = {}
bulk_data = []
total_count = 0
t1 = datetime.datetime.now()
print(t1)
i = 0
while 1:
# print(i)
i = i + 1
row = cursor.fetchone()
if not row:
break
id = row[0]
# eid = uuid.uuid4().hex[:8]
eid = "gnt" + str(id).zfill(5)
title = row[1]
if title is None: # داده های خراب
continue
title = row[1].strip()
title = text_normalize.normalize_qanon(title)
parent = row[2]
parent_id = 0
if parent != 0:
parent_id = "gnt" + str(parent).zfill(5)
child_order = row[3]
meta = row[4]
tags = row[5]
meta_info = {}
if meta:
meta_info["id1"] = str(meta)
tags_list = []
if tags:
for tt in tags.strip().split(","):
if tt and not tt in tags_list:
tags_list.append(tt)
main_type_key = "tree" + str(project_id)
data = {
"id": eid,
"version_key": "base_1",
"tree_key": main_type_key,
"tree_label": project_title,
"main_type": "tree",
"group_key" : "موضوعی",
"title": title,
"parent_id": parent_id,
"child_order": child_order,
"tags": tags_list,
"meta_info": meta_info,
}
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print(
"=" * 10,
"to_elastic , total=" + str(total_count),
str(i) + ", id=" + eid,
)
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
bulk_data.append({"_id": eid, "_source": data})
if len(bulk_data) > 0:
total_count += len(bulk_data)
print("=" * 10, " to_elastic , total=" + str(total_count))
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
print("end success import_to_elastic")
t2 = datetime.datetime.now()
print(t2 - t1)
def import_tlist_projects(index_name_o="gn_tree"):
config_env = load_dotenv(dotenv_path="./config.env")
MYSQL_username = os.getenv("MYSQL_username")
MYSQL_root_password = os.getenv("MYSQL_root_password")
MYSQL_port = os.getenv("MYSQL_port")
# MYSQL_host = os.getenv("MYSQL_import_host")
MYSQL_host = os.getenv("MYSQL_import_host_60")
# MYSQL_host = os.getenv("MYSQL_import_host_160")
cnx = mariadb.connect(user="root", password=MYSQL_root_password, host=MYSQL_host)
cursor = cnx.cursor()
query = "select id, title from tlist.tl_projects"
cursor.execute(query)
list_projects = []
while 1:
row = cursor.fetchone()
if not row:
break
pid = row[0] # "id"
title = row[1] # "title"
title = text_normalize.normalize_qanon(title)
# print(title)
# فهرست های تستی همفهمی
if pid == 4 or pid == 5 or pid == 6:
continue
# فهرستهای موضوعی استاد حسینی و استاد میرباقری که قرار شد از اکسل پورتال ارسال شود
if pid == 2 or pid == 3:
continue
# استانها و شهرها که در ایندکس دیگر ذخیره می شود
if pid == 1000:
continue
list_projects.append({"id": pid, "title": title})
for item in list_projects:
print("*" * 100)
print(item)
import_project_to_elastic(cursor, elastic, item["id"], item["title"], index_name_o)
cursor.close()
def import_option_to_elastic(
elastic,
main_key,
main_label,
group_key="عناوین انتخابی برنامه",
eid="",
index_name_o="gn_option",
):
res = get_public_options(main_key)
if not res :
res = get_monir_options(main_key)
titles = [item["value"] for item in res]
if not eid:
eid = uuid.uuid4().hex[:8]
data = {
"id": eid,
"version_key": "b1",
"main_key": main_key,
"main_label": main_label,
"group_key": group_key,
"main_type": "list_simple",
"titles": titles,
}
elastic.es.index(index=index_name_o, id=eid, document=data)
def import_option_base_list(elastic, index_name_o="gn_option"):
op_list = [
{
"main_key": "calendar_main_type",
"main_label": "تقویم- نوع اصلی",
},
{
"main_key": "calendar_media",
"main_label": "تقویم - رسانه دارد؟",
},
{
"main_key": "calendar_domain",
"main_label": "تقویم - حوزه درخواست",
},
{
"main_key": "calendar_audience",
"main_label": "تقویم - نوع مخاطبان",
},
{
"main_key": "calendar_format",
"main_label": "تقویم - قالب جلسه",
},
{
"main_key": "calendar_exec",
"main_label": "تقویم - وضعیت برگزاری",
},
{
"main_key": "calendar_accept",
"main_label": "تقویم - وضعیت پذیرش",
},
{
"main_key": "sanad_steps",
"main_label": "مراحل نگارش سند",
},
{
"main_key": "search_amplify",
"main_label": "انواع جستجوی تقویتی",
},
{
"main_key": "sanad_meta-permit",
"main_label": "سطوح دسترسی داده",
},
{
"main_key": "sanad_format",
"main_label": "قالب های جلسه",
},
{
"main_key": "fish_take_type",
"main_label": "فیش - نوع برداشت",
},
{
"main_key": "fish_text_verb",
"main_label": "فیش - نوع فعل",
},
{
"main_key": "note_take_type",
"main_label": "یادداشت - نوع برداشت",
},
]
number = 0
for op in op_list:
number = number + 1
print(op["main_key"])
eid = "mn_op_" + str(number)
group_key = "عناوین انتخابی برنامه"
if "group_key" in op:
group_key = op["group_key"]
import_option_to_elastic(
elastic, op["main_key"], op["main_label"], group_key, eid, index_name_o
)
def import_option_ostan_shahr(elastic, index_name_o="gn_option"):
file_path = './data/ostan.txt'
lines = []
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
print(len(lines))
ostan_dic={}
ostan_list = []
number = 0
for line in lines:
items = line.strip('\n').split('\t')
# print(items)
number +=1
if len(items) != 2 :
continue
ostan=items[0]
ostan = text_normalize.normalize_qanon(ostan)
shahr=items[1]
shahr = text_normalize.normalize_qanon(shahr)
if ostan not in ostan_dic:
ostan_list.append(ostan)
ostan_dic[ostan] = []
ostan_dic[ostan].append(shahr)
eid = 'iros_0'
main_key = "ir_ostan"
main_label = "استانهای ایران"
group_key = "استان و شهرهای ایران"
main_type = "list_simple"
data = {
"id": eid,
"version_key": "b1",
"main_key": main_key,
"main_label": main_label,
"group_key": group_key,
"titles": ostan_list,
}
elastic.es.index(index=index_name_o, id=eid, document=data)
number = 0
for key, value in ostan_dic.items():
number = number + 1
ostan = key
shahrs = value
eid = 'iros_' + str(number)
main_key = str(ostan)
main_label = "شهرهای استان " + ostan
group_key = "استان و شهرهای ایران"
main_type = "list_simple"
data = {
"id": eid,
"version_key": "b1",
"main_key": main_key,
"main_label": main_label,
"group_key": group_key,
"titles": shahrs,
}
elastic.es.index(index=index_name_o, id=eid, document=data)
##### -------------------------------------------------------------
def convert_excel_data_to_json(item):
_id = "gnp" + str(item["id"])
tree_label = item["person_title"]
person_id = item["person_id"]
title = item["title"]
group_key = ""
if person_id == 1103 :
group_key = "استاد حسینی"
tree_label = "فهرست موضوعی جلسات استاد حسینی"
elif person_id == 1128 :
group_key = "استاد میرباقری"
tree_label = "فهرست موضوعی جلسات استاد میرباقری"
papa_id = item["papa_id"]
if papa_id == 0:
parent_id = str(0)
else:
parent_id = "gnp" + str(papa_id)
child_order = item["order"]
return {
"id": _id, # "gnt01741"
"version_key": "portal_2",
"tree_key": "tree" + str(person_id),
"tree_label": tree_label, # "فهرست موضوعات مسائل و پاسخها",
"group_key": group_key,
"main_type": "tree",
"title": title, # "پیامدهای روبنایی",
"parent_id": parent_id,
"child_order": child_order,
"tags": [],
"meta_info": {},
}
def import_excel_tree_monir(elastic, file_path, index_name_o = "gn_tree"):
data_excel = extract_excel_fields(file_path, sheet_name="Sheet1")
print(f'data_excel {len(data_excel)}')
try:
f_data = []
for i in data_excel:
f_data.append(convert_excel_data_to_json(i))
except Exception as e:
print(
f"*************",
)
traceback.print_exc()
bulk_data=[]
total_count = 0
data_list = f_data
i = 0
for data in data_list :
eid = data["id"]
i = i + 1
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print('=' * 10, 'to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
bulk_data.append(
{
'_id' : eid,
'_source' : data
}
)
if len(bulk_data) > 0:
total_count += len(bulk_data)
print('=' * 10, ' to_elastic , total='+str(total_count) )
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
print("end success import_to_elastic")
##### -------------------------------------------------------------
if __name__ == "__main__":
###### -------------- gn_tree -----------------------------
# import_tlist_projects("gn_tree")
# file_path = r"app/../data/monir/041106_لیست تمام موضوعات.xlsx"
# import_excel_tree_monir(elastic, file_path, "gn_tree")
###### -------------- gn_option -----------------------------
# import_option_base_list(elastic, "gn_option")
# import_option_ostan_shahr(elastic, "gn_option")
###### -------------- -----------------------------
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "mn_sanad_temp", "mn_sanad")
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "mn_steps_temp", "mn_steps")
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "gn_calendar", "gn_calendar")
###### -------------- -----------------------------
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "gn_tree", "gn_tree")
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "gn_option", "gn_option")
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "mn_voice", "mn_voice")
+129
View File
@@ -0,0 +1,129 @@
def get_public_options(key, add_all_item=False):
options = []
if key == "calendar_main_type":
options = [
{"value": "اصلی"},
{"value": "پشتیبان"},
]
elif key == "calendar_media":
options = [
{"value": "دارد"},
{"value": "ندارد"},
]
elif key == "calendar_domain":
options = [
{"value": "مدیریت"},
{"value": "ارتباطات"},
{"value": "فرهنگستان"},
{"value": "حوزوی"},
{"value": "دانشگاهی"},
{"value": "نظام"},
{"value": "عمومی"},
]
elif key == "calendar_audience":
options = [
{"value": "حوزوی"},
{"value": "دانشگاهی"},
{"value": "اجرایی - نظام"},
{"value": "عمومی"},
{"value": "فرهنگستان"},
{"value": "دفتر"},
{"value": "درایه"},
{"value": "سایر سازمانها"},
]
elif key == "calendar_format":
options = [
{"value": "منبر", "title": "منبر"},
{"value": "سخنرانی", "title": "سخنرانی"},
{"value": "مشاوره", "title": "مشاوره"},
{"value": "خطبه عقد", "title": "خطبه عقد"},
{"value": "کتاب", "title": "کتاب"},
{"value": "گفتگو", "title": "گفتگو"},
{"value": "دیدار", "title": "دیدار"},
{"value": "درس خارج", "title": "درس خارج"},
{"value": "مصاحبه", "title": "مصاحبه"},
{"value": "سایر", "title": "سایر"},
]
elif key == "calendar_exec":
options = [
{"value": "برگزار شد", "title": "برگزار شد"},
{"value": "لغو از طرف استاد", "title": "لغو از طرف استاد"},
{"value": "لغو از طرف دعوت کننده", "title": "لغو از طرف دعوت کننده"},
]
elif key == "calendar_accept":
options = [
{"value": "منتظر بررسی", "title": "منتظر بررسی"},
{"value": "پذیرش", "title": "پذیرش"},
{"value": "عدم پذیرش", "title": "عدم پذیرش"},
]
if add_all_item:
options.insert(0, {"value": "all", "title": "All"})
return options
def get_monir_options(key: str, add_all_item: bool = False):
options_map = {
"sanad_steps": [
{"value": "پیاده تایپ"},
{"value": "تطبیق"},
{"value": "کنترل"},
{"value": "سند پژوهشی"},
{"value": "سند اولیه"},
{"value": "ویرایش 1"},
{"value": "متن سایت"},
{"value": "ویرایش 2"},
{"value": "سند ثانویه"},
],
"search_amplify": [
{"value": "رویکرد تعریفی", "title": "رویکرد تعریفی"},
{"value": "رویکرد استدلالی", "title": "رویکرد استدلالی"},
{"value": "رویکرد تمثیلی", "title": "رویکرد تمثیلی"},
{
"value": "تنظیم بیشتر...",
"title": "تنظیم بیشتر...",
"type": "AmplifySearch",
},
],
"sanad_meta-permit": [
{"value": "public", "title": "عمومی"},
{"value": "p1", "title": "تخصصی کم"},
{"value": "p2", "title": "تخصصی معمولی"},
{"value": "p3", "title": "تخصصی متوسط"},
{"value": "p4", "title": "تخصصی بالا"},
{"value": "p5", "title": "تخصصی چالشی بالا"},
],
"sanad_format": [
{"value": "جلسه علمی", "title": "جلسه علمی"},
{"value": "سخنرانی", "title": "سخنرانی"},
{"value": "منبر", "title": "منبر"},
{"value": "کتاب", "title": "کتاب"},
{"value": "مقاله", "title": "مقاله"},
{"value": "سایر", "title": "سایر"},
],
"fish_take_type": [
{"value": "ابهام و سوال", "title": "ابهام و سوال"},
{"value": "رفع ابهام و تشریح", "title": "رفع ابهام و تشریح"},
{"value": "سایر", "title": "سایر"},
],
"fish_text_verb": [
{"value": "نقد", "title": "نقد"},
{"value": "استدلال", "title": "استدلال"},
{"value": "تایید", "title": "تایید"},
{"value": "سوال", "title": "سوال"},
],
"note_take_type": [
{"value": "ابهام و سوال", "title": "ابهام و سوال"},
{"value": "رفع ابهام و تشریح", "title": "رفع ابهام و تشریح"},
{"value": "نقد", "title": "نقد"},
{"value": "استدلال", "title": "استدلال"},
{"value": "تعریف", "title": "تعریف"},
{"value": "سایر", "title": "سایر"},
],
}
opts = options_map.get(key, [])
if add_all_item:
opts.append({"value": "All", "title": "All"})
return opts
+153
View File
@@ -0,0 +1,153 @@
import numbers
import os
from dotenv import load_dotenv
from elasticsearch import Elasticsearch, helpers
from elasticsearch.helpers import scan
import json
import re
import time, traceback, uuid, orjson, jdatetime, re
from datetime import datetime, timezone
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
from app.common.text_normalizer import TextNormalizer
from app.common.general_functions import *
from app.common.elastic_helper import ElasticHelper
text_normal = TextNormalizer()
load_dotenv(dotenv_path='config.env')
host=os.getenv('HOST_60')
password=os.getenv('HOST_60_PASS')
# print( "---------------->>>>>>>>>>>>>>>", host )
# host=os.getenv('HOST_113')
# password=os.getenv('HOST_113_PASS')
print('.... majles_codes_update_steps ......', host)
path_base_map = "G:/Project2/gateway_php/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
index_name_o = "mn_voice"
path_files = "app/../data/monir/spr_v1/farhangestan-output"
bulk_data = []
total_count = 0
files = get_files(path_files, r"(\d+)\.json$")
# files = get_files(path_files)
for file in files :
print(file)
data = {}
try :
with open(file, "r", encoding="utf8") as f:
data = json.load(f)
eid = data["_id"]
try:
res = elastic.get_document(index_name_o, eid)
source = res["_source"]
continue
except:
pass
sound_files = data["sound_files"]
sound_link = sound_files[0]["link"]
sound_title = sound_files[0]["title"]
author = data["author"]
branch = data["branch"]
title = data["title"]
begin_date = data["begin_date"]
begin_year = data["begin_year"]
meet_code = data["meet_code"]
meet_no = data["meet_no"]
person_code = data["person_code"]
city = data["city"]
place = data["place"]
_format = data["format"]
words = []
transcript = data["transcript"]
content = ""
if transcript :
content = transcript[0]["full_text"]
words = transcript[0]["words"]
else :
if "content" in data :
content = data["content"]
if "words_align" in data :
words = data["words_align"]
content = text_normal.normalize_qanon(content)
content = content.strip().strip('\r\t\n')
word_times = []
for w in words :
word_times.append(w["start"])
data_item = {
"id": eid,
"title": title,
"author": author,
"branch": branch,
"begin_date": begin_date,
"meet_code": meet_code,
"meet_no": meet_no,
"person_code": person_code,
"city": city,
"place": place,
"format": _format,
"content": content,
"sound_link": sound_link,
"sound_title": sound_title,
"word_times" : word_times
}
bulk_data.append(
{"_id": eid, "_source": data_item}
)
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print(
"=" * 10, "to_elastic , total=" + str(total_count)
)
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []
except Exception as e:
print("error in file " + file + str(e))
if len(bulk_data) >= 0:
total_count += len(bulk_data)
print(
"=" * 10, "to_elastic , total=" + str(total_count)
)
elastic.importBulkList(bulk_data, index_name_o)
bulk_data = []