質問編集履歴

1

code追加

2020/08/04 09:32

投稿

ktg_st
ktg_st

スコア33

test CHANGED
File without changes
test CHANGED
@@ -31,3 +31,115 @@
31
31
 
32
32
 
33
33
  よろしくお願いします。
34
+
35
+
36
+
37
+ 追記
38
+
39
+
40
+
41
+ ```
42
+
43
+ def get_week_schedules(self, start, end, days):
44
+
45
+
46
+
47
+ shops= Shops.objects.all()
48
+
49
+ b =[]
50
+
51
+ for a in shops:
52
+
53
+ if a.shop in b:
54
+
55
+ pass
56
+
57
+ else:
58
+
59
+ shop=a.shop
60
+
61
+ b.append(shop)
62
+
63
+ days = {day: [] for day in days}
64
+
65
+ df = pd.DataFrame(days)
66
+
67
+
68
+
69
+ df.fillna(" ", inplace=True)
70
+
71
+ lookup = {
72
+
73
+ '{}__range'.format(self.date_field): (start, end),
74
+
75
+ }
76
+
77
+ c=[]
78
+
79
+ for shop in b:
80
+
81
+
82
+
83
+ configs = Shop_config_day.objects.filter(**lookup,shops__shop=shop)
84
+
85
+ pp=1
86
+
87
+ for config in configs:
88
+
89
+ if pp==1:
90
+
91
+ shop=config.shops.get_shop_display()
92
+
93
+ date= config.date
94
+
95
+ pa = config.day_need
96
+
97
+ fff =pd.DataFrame({date:int(pa)},index =[shop])
98
+
99
+ df = pd.concat([df,fff],axis=0)
100
+
101
+ df.fillna(" ", inplace=True)
102
+
103
+ pp=2
104
+
105
+ if shop != config.shops.get_shop_display():
106
+
107
+ shop=config.shops.get_shop_display()
108
+
109
+ date= config.date
110
+
111
+ pa = config.day_need
112
+
113
+ fff =pd.DataFrame({date:int(pa)},index =[shop])
114
+
115
+ df = pd.concat([df,fff],axis=0)
116
+
117
+ df.fillna(" ", inplace=True)
118
+
119
+ c.append(config.day_need)
120
+
121
+
122
+
123
+ else:
124
+
125
+ shop=config.shops.get_shop_display()
126
+
127
+ date= config.date
128
+
129
+ pa = config.day_need
130
+
131
+ df[date]= df[date].astype(str)
132
+
133
+ df.at[shop,date] =int(pa)
134
+
135
+ df.fillna(" ", inplace=True)
136
+
137
+ i=df.values
138
+
139
+ ret = [sum(v) for v in zip(*i)]
140
+
141
+ print(ret)
142
+
143
+
144
+
145
+ ```