Эх сурвалжийг харах

更新alexe统计
本地配置换成新服务器

chanjunkai 5 жил өмнө
parent
commit
37bac409dd

+ 6 - 6
Ansjer/config_local.py

@@ -15,12 +15,12 @@
 OAUTH_ACCESS_TOKEN_SECRET = 'local_a+jbgnw%@1%zy^=@dn62%'
 OAUTH_REFRESH_TOKEN_SECRET = 'local_r+jbgnw%@1%zy^=@dn62%'
 
-NGINX_RTMP_STAT = 'http://192.168.136.45:8077/stat'
-SERVER_DOMAIN = 'http://192.168.136.45:8077/'
-SERVER_DOMAIN_SSL = 'http://192.168.136.45:8077/'
-SERVER_HOST = '192.168.136.45'
-DOMAIN_HOST = '192.168.136.45'
-RTMP_PUSH_URL = 'rtmp://192.168.136.45:1935/hls'
+NGINX_RTMP_STAT = 'http://192.168.136.99:8077/stat'
+SERVER_DOMAIN = 'http://192.168.136.99:8077/'
+SERVER_DOMAIN_SSL = 'http://192.168.136.99:8077/'
+SERVER_HOST = '192.168.136.99'
+DOMAIN_HOST = '192.168.136.99'
+RTMP_PUSH_URL = 'rtmp://192.168.136.99:1935/hls'
 PAYPAL_CRD = {
     "mode": "sandbox",  # sandbox or live
     "client_id": "AeuhR7FHisO-lOd2OwtzyDu7PSLMmDZoDLgmzuEQ12WCtTu_8Z1AzcD4gG5SnymnuvJs-n5KBB8H9Z_G",

+ 1 - 1
Ansjer/local_settings.py

@@ -74,7 +74,7 @@ WSGI_APPLICATION = 'Ansjer.local_wsgi.application'
 
 # 服务器类型
 DATABASE_DATA = 'AnsjerLocal'
-SERVER_HOST = '192.168.136.45'
+SERVER_HOST = '192.168.136.99'
 DATABASES_USER = 'ansjer'
 DATABASES_PASS = 'ansjer.x.x'
 

+ 5 - 1
Ansjer/urls.py

@@ -10,7 +10,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     StsOssController, UIDPreview, OssCrd, SysMsg, UidUser, EquipmentManagerV2, EquipmentManagerV3, PushDeploy, \
     AppSetController, \
     ApplicationController, UserExController, CloudStorage, TestApi, UserBrandControllerV2, \
-    StatisticsController
+    StatisticsController, Alexa
 
 urlpatterns = [
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
@@ -215,6 +215,10 @@ urlpatterns = [
     # url(r'^test/add$', GenerateDataController.GenerateDataView.as_view()),
     url(r'^statistcs/appFrequencyMonth$', StatisticsController.statistcsAppFrequency),
     url(r'^statistcs/appFrequencyYear$', StatisticsController.statistcsAppFrequencyYear),
+
+    #统计alexa连接数
+    url(r'^alexa/(?P<operation>.*)$', Alexa.AlexaConnectNum.as_view()),
+
     # app 设备消息模板
     # 路由加参数参考
     # url(r'^(?P<path>.*)/(?P<UID>.*)/lls$', Test.Test.as_view(), name=u'gg'),

+ 132 - 0
Controller/Alexa.py

@@ -0,0 +1,132 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
+@AUTHOR: ASJRD018
+@NAME: Ansjer
+@software: PyCharm
+@DATE: 2020/8/14 10:13
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: AlexaConnectNum.py
+@Contact: sonalh@foxmail.com
+"""
+from django.views.generic.base import View
+import os
+
+import json
+import math
+import time
+import urllib
+import logging
+import logging
+import requests
+import time
+import datetime
+from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
+from Model.models import AlexaConnectStatisticsModel
+from django.views.generic import TemplateView
+from django.utils.decorators import method_decorator
+from django.views.decorators.csrf import csrf_exempt
+from django.views.generic.base import View
+from django.contrib.auth.hashers import make_password, check_password  # 对密码加密模块
+from Object.ResponseObject import ResponseObject
+from Object.TokenObject import TokenObject
+from Service.ModelService import ModelService
+from django.db import connection
+
+rtspServer = "rtsp.zositech.org,3.16.66.144"
+
+# 获取alexa连接数接口
+class AlexaConnectNum(TemplateView):
+    @method_decorator(csrf_exempt)
+    def dispatch(self, *args, **kwargs):
+        return super(AlexaConnectNum, self).dispatch(*args, **kwargs)
+
+    def get(self, request, *args, **kwargs):
+        response = ResponseObject()
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        #每隔十分钟定时保存每天最高连接数,crontab 在alexa_oauth2_oserver
+        if operation == 'saveConnectNum':
+            today = datetime.date.today()
+            today_start_time = int(time.mktime(time.strptime(str(today), '%Y-%m-%d')))
+            today_end_time = int(time.mktime(time.strptime(str(today), '%Y-%m-%d'))) + 86399
+             #获取当前连接数
+            current_connect_num = self.currentConnect()
+            today_data = AlexaConnectStatisticsModel.objects.\
+                filter(data_time__lte=today_end_time,data_time__gte=today_start_time).values('num','data_time')
+            if today_data.exists():
+                num = list(today_data)[0]['num']
+                if current_connect_num > num:
+                    today_data.update(num=current_connect_num, data_time=time.time())
+            else:
+                today_data.create(num=current_connect_num, data_time=time.time())
+            return response.json(0)
+        return response.json(10006)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        response = ResponseObject()
+        operation = kwargs.get('operation')
+        post_data = request.POST
+        token = post_data.get('token', None)
+        # tko = TokenObject()
+        # newToken = tko.generate( data={'userID': '158943594633713800138000', 'lang': 'cn', 'user': '597471180@qq.com', 'm_code': '123413243214'})
+        # return response.json(0, {'data': newToken})
+        tko = TokenObject(token)
+        response.lang = tko.lang
+        if tko.code != 0:
+            return response.json(tko.code)
+        userID = tko.userID
+        own_permission = ModelService.check_perm(userID=userID, permID=30)
+        if own_permission is not True:
+            return response.json(404)
+
+        #获取当前连接数
+        current_connect_num = self.currentConnect()
+        res = []
+        #最近三十天每天最高连接数
+        if operation == 'thirtyDays':
+            query_num = AlexaConnectStatisticsModel.objects.\
+                extra(select={"data_time": "FROM_UNIXTIME(data_time, '%%m-%%d')"}).\
+                values('num', 'data_time').order_by('-data_time')[:30]
+            res = list(query_num)
+
+        #最近十二个月每月最高连接数
+        if operation == 'years':
+            cursor=connection.cursor()
+            cursor.execute("SELECT FROM_UNIXTIME(data_time,'%Y-%m') as month, max(num) as max_num FROM alexa_statistics GROUP BY month order by month asc")
+            res_query = cursor.fetchall()
+            for max_num, month in res_query:
+                res.append({'num':max_num, 'month':month})
+
+        res_desc = {'result_code': 0, 'reason': '成功', 'current_num':current_connect_num, 'top_num': res, 'error_code': 0}
+        result_json = json.dumps(res_desc, ensure_ascii=False)
+        return HttpResponse(result_json)
+
+    def currentConnect(self):
+        urls = rtspServer.split(',')
+        httpPrefix = 'http://'
+        postfix = ':10008/api/v1/pushers'
+        current_connect_num = 0
+        for url in urls:
+            apiUrl = httpPrefix + url + postfix
+            try:
+                selectRtsp = requests.get(url=apiUrl, timeout=5)
+                current_connect_num += selectRtsp.json()['total']
+            except Exception as e:
+                continue
+        return current_connect_num
+
+
+
+
+
+
+
+
+
+
+
+

+ 6 - 2
Controller/TestApi.py

@@ -35,6 +35,7 @@ from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
 from django.utils.decorators import method_decorator
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic.base import View
+from django.contrib.auth.hashers import make_password, check_password  # 对密码加密模块
 
 from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN, PAYPAL_CRD, \
     SERVER_DOMAIN_SSL
@@ -76,8 +77,8 @@ class testView(View):
         if operation is None:
             return response.json(444, 'error path')
         elif operation == 'tests':
-            userID  = '158943594633713800138000'
-            return self.do_filter_playlist(request_dict, userID, response)
+             res = make_password(123456)
+             return JsonResponse(status=200, data=res,safe=False)
         elif operation == 'cbu':
             return self.createBucket()
         elif operation == 'vodList':
@@ -92,6 +93,9 @@ class testView(View):
         elif operation == 'eqi_query':
             userID = '158943594633713800138000'
             return self.queryInterface(request_dict, userID, response)
+        elif operation == 'getAlexa':
+            userID = '158943594633713800138000'
+            return self.queryInterface(request_dict, userID, response)
         else:
             return 12344444
 

+ 11 - 0
Model/models.py

@@ -947,3 +947,14 @@ class AppFrequencyYearStatisticsModel(models.Model):
         verbose_name = 'app使用频率统计表,年度统计'
         verbose_name_plural = verbose_name
         db_table = 'app_frequency_year_statistics'
+
+# alexa连接数统计表
+class AlexaConnectStatisticsModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    num = models.IntegerField(default=0, verbose_name='总人数')
+    data_time = models.IntegerField(default=0, verbose_name='数据时间')
+
+    class Meta:
+        verbose_name = 'alexa连接数统计表'
+        verbose_name_plural = verbose_name
+        db_table = 'alexa_statistics'