zoukankan      html  css  js  c++  java
  • 【数据结构的补全整理】规定在周一到周五中,赛选出8点到18点中的计划安排,空计划时刻补全空值

    # 数据表的设计
    
    class ProMeetTable(models.Model):
        """
            个人安排表
        """
        user = models.ForeignKey(to="UserInfo",verbose_name="所属用户")
        week_choice = (
            (1,"Monday"),
            (2,"Tuesday"),
            (3,"Wednesday"),
            (4,"Thursday"),
            (5,"Friday"),
        )
        week = models.IntegerField(choices=week_choice,verbose_name="星期")
        time_choice = (
            (1, "08:00"),
            (2, "09:00"),
            (3, "10:00"),
            (4, "11:00"),
            (5, "12:00"),
            (6, "13:00"),
            (7, "14:00"),
            (8, "15:00"),
            (9, "16:00"),
            (10, "17:00"),
            (11, "18:00"),
        )
        time = models.IntegerField(choices=week_choice, verbose_name="时刻")
        title = models.CharField(max_length=250,verbose_name="安排",null=True,blank=True)
    
        def __str__(self):
            return self.title
    
        class Meta:
            verbose_name = "ProMeetTable"
            verbose_name_plural = verbose_name
            db_table = 'ProMeetTable'



    # 假设设计好的个人安排数据

     
    # 接口:


    class
    ProData(APIView): authentication_classes = [] def post(self,request): message = {} week= [1,2,3,4,5] id = int(request.data.get("id")) ProTime = [] # 遍历每个时刻 for x in [8,9,10,11,12,13,14,15,16,17,18]: ProMeetTableRaw = models.ProMeetTable.objects.filter(user_id=id,time=x).all() week_plan = [] for table in ProMeetTableRaw: week_plan.append(table.week) # 遍历计算出每个时刻空内容的星期 创建一个空包在数据库内 for week_set in set(week).difference(set(week_plan)): models.ProMeetTable.objects.create(week=week_set,time=x,user_id=id,title="") # 根据时刻 将周一到周五全部抽出来 ProMeetTableSet = models.ProMeetTable.objects.filter(user_id=id,time=x).all().order_by("week") data_f = {} data_f["time"] = "{}:00".format(x) for table in ProMeetTableSet: data_f[self.type_week(table.week)] = table.title ProTime.append(data_f) # 删除所有空字段 models.ProMeetTable.objects.filter(user_id=id, title="").all().delete() message['code'] = 200 message['data'] = ProTime return JsonResponse(message) def type_time(self, item): data = {8: "08:00",9: "09:00",10: "10:00",11: "11:00",12: "12:00",13: "13:00",14: "14:00", 15: "15:00",16: "16:00",17: "17:00",18: "18:00",} res = data[item] return res def type_week(self, item): data = {1: "Monday",2: "Tuesday",3: "Wednesday",4: "Thursday",5: "Friday",} res = data[item] return res



    # 数据渲染


    总结:有时候数据结构不方便的时候可以借助数据库(这里建议使用内存型数据库)来整理数据结构也是不错的选择

  • 相关阅读:
    Pandas高级教程之:category数据类型
    Pandas高级教程之:处理缺失数据
    Pandas高级教程之:处理text数据
    密码学系列之:blowfish对称密钥分组算法
    架构之:数据流架构
    ES6中的新特性:Iterables和iterators
    密码学系列之:feistel cipher
    Pandas高级教程之:Dataframe的重排和旋转
    Electron实用技巧-electron-builder中用户协议(license)的使用及多语言支持
    Electron实用技巧-开机启动时隐藏主窗口,只显示系统托盘
  • 原文地址:https://www.cnblogs.com/wanghong1994/p/13948905.html
Copyright © 2011-2022 走看看