The design and implementation of django Python based epidemic data visualization analysis system (source code debugging+code explanation+document report)

πŸ’•πŸ’• Author: Computer Source Code Society
πŸ’•πŸ’• Profile: I have seven years of development experience and am good at Java, WeChat applet, Python, Android, etc. If you have any questions about this, you can communicate with me!
πŸ’•πŸ’• Learning materials, program development, technical answers, code explanations, document reports

πŸ’•πŸ’•Java Web Project
πŸ’•πŸ’•WeChat applet project
πŸ’•πŸ’•Python project
πŸ’•πŸ’•Android project

1. Project introduction

Today, with the rapid development of the Internet, every field of our life involves the application of computers, including the network application of the epidemic data visualization analysis system, which has been a very common way in foreign online management systems, but the domestic management system may still be in its infancy. The epidemic data visualization analysis system has the choice of the epidemic data visualization analysis information management function. The epidemic data visualization analysis system adopts Django framework and is developed based on mysql. It realizes home page, personal center, user management, employee management, epidemic information management, nucleic acid detection management, detection appointment management, detection result management, travel information management, system management, etc.
This design task is to design a Python based epidemic data visualization analysis system, which can meet the epidemic data visualization analysis sharing function of administrators, employees and users of the epidemic data visualization analysis. The administrator can log in according to the account given by the system. After logging in, the administrator can enter the epidemic data visualization analysis system to manage all functions of the epidemic data visualization analysis system.

2. Core functional modules

Through the above functional analysis, the functions of the epidemic data visualization analysis system can be divided into three parts: administrator, employee and user. The main functions of the system include home page, personal center, user management, employee management, epidemic information management, nucleic acid detection management, detection appointment management, detection result management, travel information management, system management, etc. Information that can be browsed by any user as long as he/she enters the system without logging in. Background management is designed for the logged in users to see satisfactory visual analysis information of epidemic data.
1. Functions and permissions of general users
Ordinary users refer to those who have not registered yet and can browse the information on the main page. However, if you have desirable information about the visual analysis of epidemic data, you need to log in and register. Only if the registration is successful can you have permission.
2. Functions and permissions of the administrator
The addition and management of user information, the addition and management of detailed information on the visual analysis of epidemic data, the addition and management of document information, and the management of system information are all functions of the administrator.
The whole design structure of the Python based epidemic data visualization analysis system is shown in the figure below.

3. Project display









4. Document report directory

6. Core code

def jiancejieguo_list(request):
    '''
    Front page
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code,  "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
        req_dict = request.session.get("req_dict")

        #Get all column names
        columns=  jiancejieguo.getallcolumn( jiancejieguo, jiancejieguo)
        #Table attribute [foreEndList] foreground list: similar to the default list list page in the background, but placed in the foreground. No: there is no such page; Yes: there is such a page (you can view it without logging in); Previous login: there is such a page and you can view it only after logging in
        try:
            __foreEndList__=jiancejieguo.__foreEndList__
        except:
            __foreEndList__=None

        if __foreEndList__=="I have to register before":
            tablename=request.session.get("tablename")
            if tablename!="users" and 'userid' in columns:
                try:
                    req_dict['userid']=request.session.get("params").get("id")
                except:
                    pass
        #forrEndListAuth
        try:
            __foreEndListAuth__=jiancejieguo.__foreEndListAuth__
        except:
            __foreEndListAuth__=None


        #authSeparate
        try:
            __authSeparate__=jiancejieguo.__authSeparate__
        except:
            __authSeparate__=None

        if __foreEndListAuth__ =="yes" and __authSeparate__=="yes":
            tablename=request.session.get("tablename")
            if tablename!="users":
                req_dict['userid']=request.session.get("params",{"id":0}).get("id")

        tablename = request.session.get("tablename")
        if tablename == "users" and req_dict.get("userid") != None:#Determine whether there is a userid column name
            del req_dict["userid"]
        else:
            __isAdmin__ = None

            allModels = apps.get_app_config('main').get_models()
            for m in allModels:
                if m.__tablename__==tablename:

                    try:
                        __isAdmin__ = m.__isAdmin__
                    except:
                        __isAdmin__ = None
                    break

            if __isAdmin__ == "yes":
                if req_dict.get("userid"):
                    del req_dict["userid"]
            else:
                #For a table with non administrator permissions, determine whether the field name of the current table has a userid
                if "userid" in columns:
                    try:
                        pass
                        # This interface can be accessed anonymously, so try to determine whether it is anonymous
                        #req_dict['userid']=request.session.get("params").get("id")
                    except:
                            pass
        #When the column attribute authTable has a value (a user table) [the column name of the column must be consistent with the login field name of the user table], then the corresponding table has a hidden attribute authTable of "Yes", so the user can only view his own
        try:
            __authTables__=jiancejieguo.__authTables__
        except:
            __authTables__=None

        if __authTables__!=None and  __authTables__!={} and __foreEndListAuth__=="yes":
            try:
                del req_dict['userid']
            except:
                pass
            for authColumn,authTable in __authTables__.items():
                if authTable==tablename:
                    params = request.session.get("params")
                    req_dict[authColumn]=params.get(authColumn)
                    break
        
        if jiancejieguo.__tablename__[:7]=="discuss":
            try:
                del req_dict['userid']
            except:
                pass


        msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
        msg['data']['pageSize']  = jiancejieguo.page(jiancejieguo, jiancejieguo, req_dict)

        return JsonResponse(msg)

def jiancejieguo_save(request):
    '''
    Background addition
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
        req_dict = request.session.get("req_dict")
        if 'clicktime' in req_dict.keys():
            del req_dict['clicktime']
        tablename=request.session.get("tablename")
        __isAdmin__ = None
        allModels = apps.get_app_config('main').get_models()
        for m in allModels:
            if m.__tablename__==tablename:

                try:
                    __isAdmin__ = m.__isAdmin__
                except:
                    __isAdmin__ = None
                break


        #Get all column names
        columns=  jiancejieguo.getallcolumn( jiancejieguo, jiancejieguo)
        if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns  and __isAdmin__!='yes':
            params=request.session.get("params")
            req_dict['userid']=params.get('id')


        error= jiancejieguo.createbyreq(jiancejieguo,jiancejieguo, req_dict)
        if error!=None:
            msg['code'] = crud_error_code
            msg['msg'] = error

        return JsonResponse(msg)


def jiancejieguo_add(request):
    '''
    New foreground
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
        req_dict = request.session.get("req_dict")

        #Get all column names
        columns=  jiancejieguo.getallcolumn( jiancejieguo, jiancejieguo)
        try:
            __authSeparate__=jiancejieguo.__authSeparate__
        except:
            __authSeparate__=None

        if __authSeparate__=="yes":
            tablename=request.session.get("tablename")
            if tablename!="users" and 'userid' in columns:
                try:
                    req_dict['userid']=request.session.get("params").get("id")
                except:
                    pass

        try:
            __foreEndListAuth__=jiancejieguo.__foreEndListAuth__
        except:
            __foreEndListAuth__=None

        if __foreEndListAuth__ and __foreEndListAuth__!="no":
            tablename=request.session.get("tablename")
            if tablename!="users":
                req_dict['userid']=request.session.get("params").get("id")

        error= jiancejieguo.createbyreq(jiancejieguo,jiancejieguo, req_dict)
        if error!=None:
            msg['code'] = crud_error_code
            msg['msg'] = error
        return JsonResponse(msg)

def jiancejieguo_thumbsup(request,id_):
    '''
     Like: table attribute thumbsUp[yes/no],New table thumbsupnum approve crazilynum Step on the field,
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
        req_dict = request.session.get("req_dict")
        id_=int(id_)
        type_=int(req_dict.get("type",0))
        rets=jiancejieguo.getbyid(jiancejieguo,jiancejieguo,id_)

        update_dict={
        "id":id_,
        }
        if type_==1:#fabulous
            update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
        elif type_==2:#step on
            update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
        error = jiancejieguo.updatebyparams(jiancejieguo,jiancejieguo, update_dict)
        if error!=None:
            msg['code'] = crud_error_code
            msg['msg'] = error
        return JsonResponse(msg)


def jiancejieguo_info(request,id_):
    '''
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}

        data = jiancejieguo.getbyid(jiancejieguo,jiancejieguo, int(id_))
        if len(data)>0:
            msg['data']=data[0]
        #Browse clicks
        try:
            __browseClick__= jiancejieguo.__browseClick__
        except:
            __browseClick__=None

        if __browseClick__=="yes"  and  "clicknum"  in jiancejieguo.getallcolumn(jiancejieguo,jiancejieguo):
            try:
                clicknum=int(data[0].get("clicknum",0))+1
            except:
                clicknum=0+1
            click_dict={"id":int(id_),"clicknum":clicknum}
            ret=jiancejieguo.updatebyparams(jiancejieguo,jiancejieguo,click_dict)
            if ret!=None:
                msg['code'] = crud_error_code
                msg['msg'] = ret
        return JsonResponse(msg)

def jiancejieguo_detail(request,id_):
    '''
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}

        data =jiancejieguo.getbyid(jiancejieguo,jiancejieguo, int(id_))
        if len(data)>0:
            msg['data']=data[0]

        #Browse clicks
        try:
            __browseClick__= jiancejieguo.__browseClick__
        except:
            __browseClick__=None

        if __browseClick__=="yes"   and  "clicknum"  in jiancejieguo.getallcolumn(jiancejieguo,jiancejieguo):
            try:
                clicknum=int(data[0].get("clicknum",0))+1
            except:
                clicknum=0+1
            click_dict={"id":int(id_),"clicknum":clicknum}

            ret=jiancejieguo.updatebyparams(jiancejieguo,jiancejieguo,click_dict)
            if ret!=None:
                msg['code'] = crud_error_code
                msg['msg'] = retfo
        return JsonResponse(msg)


def jiancejieguo_update(request):
    '''
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
        req_dict = request.session.get("req_dict")
        if req_dict.get("mima") and req_dict.get("password"):
            if "mima" not  in jiancejieguo.getallcolumn(jiancejieguo,jiancejieguo) :
                del req_dict["mima"]
            if  "password" not  in jiancejieguo.getallcolumn(jiancejieguo,jiancejieguo) :
                del req_dict["password"]
        try:
            del req_dict["clicknum"]
        except:
            pass


        error = jiancejieguo.updatebyparams(jiancejieguo, jiancejieguo, req_dict)
        if error!=None:
            msg['code'] = crud_error_code
            msg['msg'] = error
        return JsonResponse(msg)


def jiancejieguo_delete(request):
    '''
    Batch deletion
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
        req_dict = request.session.get("req_dict")

        error=jiancejieguo.deletes(jiancejieguo,
            jiancejieguo,
             req_dict.get("ids")
        )
        if error!=None:
            msg['code'] = crud_error_code
            msg['msg'] = error
        return JsonResponse(msg)


def jiancejieguo_vote(request,id_):
    '''
    Browse hits (table attribute[browseClick:yes/no],Click Field( clicknum),call info/detail The backend automatically performs the interface+1),Voting function (table attribute[vote:yes/no],Voting field( votenum),call vote Interface backend votenum+1)
Count the number of clicks on goods or news; Provide voting function for news
    '''
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": mes.normal_code}


        data= jiancejieguo.getbyid(jiancejieguo, jiancejieguo, int(id_))
        for i in data:
            votenum=i.get('votenum')
            if votenum!=None:
                params={"id":int(id_),"votenum":votenum+1}
                error=jiancejieguo.updatebyparams(jiancejieguo,jiancejieguo,params)
                if error!=None:
                    msg['code'] = crud_error_code
                    msg['msg'] = error
        return JsonResponse(msg)

def jiancejieguo_importExcel(request):
    if request.method in ["POST", "GET"]:
        msg = {"code": normal_code, "msg": "success", "data": {}}

        excel_file = request.FILES.get("file", "")
        file_type = excel_file.name.split('.')[1]
        
        if file_type in ['xlsx', 'xls']:
            data = xlrd.open_workbook(filename=None, file_contents=excel_file.read())
            table = data.sheets()[0]
            rows = table.nrows
            
            try:
                for row in range(1, rows):
                    row_values = table.row_values(row)
                    req_dict = {}
                    jiancejieguo.createbyreq(jiancejieguo, jiancejieguo, req_dict)
                    
            except:
                pass
                
        else:
            msg.code = 500
            msg.msg = "Wrong file type"
                
        return JsonResponse(msg)

def jiancejieguo_sendemail(request):
    if request.method in ["POST", "GET"]:
        req_dict = request.session.get("req_dict")

        code = random.sample(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], 4)
        to = []
        to.append(req_dict['email'])

        send_mail('User Registration', 'Your registration verification code is['+''.join(code)+'],Please do not disclose the verification code to others, and do not operate without yourself.', 'yclw9@qq.com', to, fail_silently = False)

        cursor = connection.cursor()
        cursor.execute("insert into emailregistercode(email,role,code) values('"+req_dict['email']+"','user','"+''.join(code)+"')")

        msg = {
            "msg": "Sending succeeded",
            "code": 0
        }

        return JsonResponse(msg)

Tags: MySQL Python Django

Posted by bengan on Thu, 15 Sep 2022 23:18:56 +0530