質問編集履歴
1
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -113,3 +113,95 @@
|
|
113
113
|
```
|
114
114
|
|
115
115
|
の部分には3つずつ古いもの順にデータが入るようにしたいです。どのようにコードを書けば期待通りのプログラムが作れますか?
|
116
|
+
|
117
|
+
現在コードは
|
118
|
+
|
119
|
+
```ここに言語を入力
|
120
|
+
|
121
|
+
@login_required
|
122
|
+
|
123
|
+
def past_result(request):
|
124
|
+
|
125
|
+
return render(request, 'past_result.html', {'chart': _view_plot(request)})
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def _view_plot(request):
|
130
|
+
|
131
|
+
results = TestAndUser.objects.filter(user=request.user).order_by('-date')
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
print(results)
|
136
|
+
|
137
|
+
dates = [r.consultation_date for r in reversed(tcresults)]
|
138
|
+
|
139
|
+
heights = [r.tc for r in reversed(tcresults)]
|
140
|
+
|
141
|
+
scores = [i + 1 for i in range(len(heights))]
|
142
|
+
|
143
|
+
if len(scores) > 5:
|
144
|
+
|
145
|
+
dates = dates[:5]
|
146
|
+
|
147
|
+
heights = heights[:5]
|
148
|
+
|
149
|
+
scores = scores[:5]
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
image_data =[]
|
154
|
+
|
155
|
+
for i in range(len(scores)):
|
156
|
+
|
157
|
+
if scores[i] != None :
|
158
|
+
|
159
|
+
image_data.append(scores[i])
|
160
|
+
|
161
|
+
image_data.append(dates[i])
|
162
|
+
|
163
|
+
image_data.append(heights[i])
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
image_scores =[]
|
168
|
+
|
169
|
+
image_dates = []
|
170
|
+
|
171
|
+
image_heights = []
|
172
|
+
|
173
|
+
for j in range(0,len(image_data),3):
|
174
|
+
|
175
|
+
image_scores.append(image_data[j])
|
176
|
+
|
177
|
+
image_dates.append(image_data[j+1])
|
178
|
+
|
179
|
+
image_heights.append(image_data[j+2])
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
plt.plot(image_scores, image_heights)
|
186
|
+
|
187
|
+
plt.xticks(image_scores, image_dates)
|
188
|
+
|
189
|
+
plt.fill_between(x=np.arange(1, 5, 0.01), y1=60, y2=100, facecolor='yellow', alpha=0.2)
|
190
|
+
|
191
|
+
jpg_image_buffer = cStringIO.StringIO()
|
192
|
+
|
193
|
+
plt.savefig(jpg_image_buffer)
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
array = base64.b64encode(jpg_image_buffer.getvalue())
|
198
|
+
|
199
|
+
jpg_image_buffer.close()
|
200
|
+
|
201
|
+
return array
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
と書きました。
|
206
|
+
|
207
|
+
print(results)ではdateの新しいもの順に<QuerySet [<TestAndUser: xxx 59>, <TestAndUser: xxx 58>, <TestAndUser: xxx 54>, <TestAndUser: xxx 52>, <TestAndUser: xxx 50>, <TestAndUser: kadena xxx>]> と表示されました。
|