Skip to content

Commit

Permalink
完善网元名称提取
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangjiahe committed Jan 4, 2019
1 parent 828a8a5 commit 9d444c0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*/.idea/
.idea/
.idea/
utils/check_top10ne.py
2 changes: 1 addition & 1 deletion report/statistics_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get(self, request, year, month):
st = datetime.datetime.now()
result_json = dict()
try:
profession_list = ['Net_4G', 'Repeater', 'Net_CDMA', 'Transmission', 'Net_Optical', 'Dynamics', 'Exchange', 'Data']
profession_list = ['Net_4G', 'Repeater', 'Net_CDMA', 'Transmission', 'Net_Optical', 'Dynamics', 'Exchange', 'Data', 'Wifi']
rs_dict = dict()
qs = StatisticsTop10Ne.objects.filter(yearNum=year, monthNum=month)
if qs:
Expand Down
34 changes: 19 additions & 15 deletions utils/data_collect_AN.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,29 @@ def get_top10_ne(begin_datetime, end_datetime, profession):
malfunctionSource='集中告警系统报故障',
type='处理',
ne__isnull=False) \
.exclude(ne='') \
.values('city', 'ne') \
.annotate(distributeAmount=Count('ne')) \
.order_by('distributeAmount') \
.reverse()[:10]
.exclude(ne='') \
.values('city', 'ne') \
.annotate(distributeAmount=Count('ne')) \
.order_by('distributeAmount') \
.reverse()
rs_list = []
last_amount = 0
index = 0
for q in qs:
if q.get('distributeAmount', '') != last_amount:
index += 1
item = dict(
index=index,
city=q.get('city', ''),
ne=q.get('ne', ''),
distributeAmount=str(q.get('distributeAmount'))
)
last_amount = q.get('distributeAmount')
rs_list.append(item)
if q.get('distributeAmount', '') == last_amount or len(rs_list) < 10:

if q.get('distributeAmount', '') != last_amount:
index += 1
item = dict(
index=index,
city=q.get('city', ''),
ne=q.get('ne', ''),
distributeAmount=str(q.get('distributeAmount'))
)
last_amount = q.get('distributeAmount')
rs_list.append(item)
else:
break
rs_dict = {profession: rs_list}

return rs_dict
Expand Down
13 changes: 10 additions & 3 deletions utils/data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def parse_malfunction_data_xlsx(filename=None, has_repeat_data=True):
title = title[:500]
if title.__contains__('条告警(含'):
# print(title)
pattern = re.compile(r'(\d+条告警)')
pattern = re.compile(r'(\(\d+条告警)')
index = title.index(re.search(pattern, title).group(1))
title = title[:index]
malfunctionData.title = title
Expand Down Expand Up @@ -196,12 +196,18 @@ def parse_malfunction_data_xlsx(filename=None, has_repeat_data=True):
malfunctionData.originProfession = 'Data'
if malfunctionSource == '集中告警系统报故障' and mtype == '处理':
malfunctionData.ne = fetch_DataNetwork(title)
elif category.__contains__('WLAN网络'):
malfunctionData.originProfession = 'Wifi'
if malfunctionSource == '集中告警系统报故障' and mtype == '处理':
malfunctionData.ne = fetch_WIFI(title)
if profession == '动力' and malfunctionSource == '集中告警系统报故障' and mtype == '处理':
malfunctionData.originProfession = 'Dynamics'
malfunctionData.ne = fetch_Dynamic(title)
# print(str(row[field_list.index('派单时间')].value)[:19])
malfunctionData.distributeTime = datetime.datetime.strptime(str(row[field_list.index('派单时间')].value)[:19], '%Y-%m-%d %H:%M:%S')
processTime = row[field_list.index('处理时长(分钟)')].value
if processTime:
malfunctionData.distributeTime += datetime.timedelta(minutes=processTime)
malfunctionData.processTime = processTime if processTime else 0
hangTime = row[field_list.index('挂起时长(分钟)')].value
malfunctionData.hangTime = hangTime if hangTime else 0
Expand Down Expand Up @@ -246,7 +252,8 @@ def parse_malfunction_data_xlsx(filename=None, has_repeat_data=True):
except IntegrityError:
status = '有重复数据,请选择"替换导入"方式'
raise Exception(status)
MalfunctionData.objects.bulk_create(malfunctionList)
if malfunctionList:
MalfunctionData.objects.bulk_create(malfunctionList)


# 解析"指标.xls"
Expand Down Expand Up @@ -393,4 +400,4 @@ def parse_malfunction_track(file_contents):
item[0].receiptStatus = receiptStatus
item[0].city = city
item[0].createTime = createTime
item[0].save()
item[0].save()
8 changes: 4 additions & 4 deletions utils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
def export_top10ne(year, month):
begin_date = datetime.datetime(year, month, 1, 0, 0, 0)
end_datetime = datetime.datetime(year, month, calendar.mdays[month], 23, 59, 59)
profession_list = ['Net_4G', 'Repeater', 'Net_CDMA', 'Transmission', 'Net_Optical', 'Dynamics', 'Exchange', 'Data']
professions = ['4G网络', '直放站', 'CDMA网络', '传输专业', '光网络专业', '动力专业', '交换专业', '数据专业']
profession_list = ['Net_4G', 'Repeater', 'Net_CDMA', 'Transmission', 'Net_Optical', 'Dynamics', 'Exchange', 'Data', 'Wifi']
professions = ['4G网络', '直放站', 'CDMA网络', '传输专业', '光网络专业', '动力专业', '交换专业', '数据专业', 'WIFI']
wb = Workbook()
# 8个专业
for x in range(0, 8):
# 9个专业
for x in range(0, len(profession_list)):
top10_qs = StatisticsTop10Ne.objects.filter(yearNum=year, monthNum=month, profession=profession_list[x]).order_by('index').values('ne')
ne_list = []
for i in top10_qs:
Expand Down
28 changes: 23 additions & 5 deletions utils/fetch_Ne.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def fetch_4G(title):
if res:
ne = res.group(2)
return ne
elif title.__contains__('高频小区退服站点:'):
pattern = re.compile(r'(高频小区退服站点:)?(.*?)(【.*】)')
res = re.search(pattern, title)
if res:
ne = res.group(2)
return ne
else:
return ""

Expand Down Expand Up @@ -86,7 +92,7 @@ def fetch_TransmissionNetwork(title):


def fetch_OpticalNetwork(title):
pattern = re.compile(r'(.*Ne=)(.*?)(【.*|$)')
pattern = re.compile(r'(.*Ne=)(.*?)((【.*|$)|(\(\d+条.*))')
ne = re.search(pattern, title)
if ne:
return ne.group(2)
Expand All @@ -100,7 +106,7 @@ def fetch_OpticalNetwork(title):


def fetch_SwitchNetwork(title):
if title.__contains__('Ne=') and not title.__contains__('网元号'):
if title.__contains__('Ne='): # and not title.__contains__('网元号'):
pattern = re.compile(r'(.*Ne=)(.*?)/')
ne = re.search(pattern, title)
if ne:
Expand All @@ -116,7 +122,7 @@ def fetch_SwitchNetwork(title):
pattern = re.compile(r'(.*?:)(.*?):.*')
ne = re.search(pattern, title)
if ne:
return ne.group(2)
return ne.group(2).strip()
return ''


Expand Down Expand Up @@ -158,15 +164,26 @@ def fetch_Dynamic(title):
return ''


# 数据专业
def fetch_DataNetwork(title):
pattern = re.compile(r'(.*Ne=)(.*?)(/|SW断网故障|$)')
pattern = re.compile(r'(.*Ne=)(.*?)(/|SW断网故障|$|(\(\d条.*))')
ne = re.search(pattern, title)
if ne:
return ne.group(2)
else:
return ''


# WIFI专业
def fetch_WIFI(title):
pattern = re.compile(r'(.*)(—AP(WLAN))')
ne = re.search(pattern, title)
if ne:
return ne.group(1)
else:
return ''


# /PowerSystem=广州科技动力网管/Station=沙溪IDC一期(-1F、1F、3F)/Ne=IDC/Group=动环监控/TT-CC=998-120线路检测(一层高压2系统)

# /Ems=东莞爱默生电源专业网管/Station=石鼓七D-综合机房环境综合机房环境:综合机房1号温度::温度过高
Expand All @@ -185,4 +202,5 @@ def fetch_DataNetwork(title):
# pattern = re.compile(r'(.*基站断站:?|.*小区退服:|【VIP站点】)?(.*?)—eNodeB—(.*)')
# ne = re.search(pattern, title)
# print(ne.groups())

if __name__ == '__main__':
print(fetch_WIFI('ZS-WG-KJZ-0001—AP(WLAN)—AP无法连通告警'))

0 comments on commit 9d444c0

Please sign in to comment.