質問編集履歴
1
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -55,4 +55,50 @@
|
|
55
55
|
dates = [results[4].date, results[3].date, results[2].date, results[1].date, results[0].date]
|
56
56
|
heights = [results[4].score,results[3].score,results[2].score, results[1].score,results[0].score]
|
57
57
|
```
|
58
|
-
の部分には3つずつ古いもの順にデータが入るようにしたいです。どのようにコードを書けば期待通りのプログラムが作れますか?
|
58
|
+
の部分には3つずつ古いもの順にデータが入るようにしたいです。どのようにコードを書けば期待通りのプログラムが作れますか?
|
59
|
+
現在コードは
|
60
|
+
```ここに言語を入力
|
61
|
+
@login_required
|
62
|
+
def past_result(request):
|
63
|
+
return render(request, 'past_result.html', {'chart': _view_plot(request)})
|
64
|
+
|
65
|
+
def _view_plot(request):
|
66
|
+
results = TestAndUser.objects.filter(user=request.user).order_by('-date')
|
67
|
+
|
68
|
+
print(results)
|
69
|
+
dates = [r.consultation_date for r in reversed(tcresults)]
|
70
|
+
heights = [r.tc for r in reversed(tcresults)]
|
71
|
+
scores = [i + 1 for i in range(len(heights))]
|
72
|
+
if len(scores) > 5:
|
73
|
+
dates = dates[:5]
|
74
|
+
heights = heights[:5]
|
75
|
+
scores = scores[:5]
|
76
|
+
|
77
|
+
image_data =[]
|
78
|
+
for i in range(len(scores)):
|
79
|
+
if scores[i] != None :
|
80
|
+
image_data.append(scores[i])
|
81
|
+
image_data.append(dates[i])
|
82
|
+
image_data.append(heights[i])
|
83
|
+
|
84
|
+
image_scores =[]
|
85
|
+
image_dates = []
|
86
|
+
image_heights = []
|
87
|
+
for j in range(0,len(image_data),3):
|
88
|
+
image_scores.append(image_data[j])
|
89
|
+
image_dates.append(image_data[j+1])
|
90
|
+
image_heights.append(image_data[j+2])
|
91
|
+
|
92
|
+
|
93
|
+
plt.plot(image_scores, image_heights)
|
94
|
+
plt.xticks(image_scores, image_dates)
|
95
|
+
plt.fill_between(x=np.arange(1, 5, 0.01), y1=60, y2=100, facecolor='yellow', alpha=0.2)
|
96
|
+
jpg_image_buffer = cStringIO.StringIO()
|
97
|
+
plt.savefig(jpg_image_buffer)
|
98
|
+
|
99
|
+
array = base64.b64encode(jpg_image_buffer.getvalue())
|
100
|
+
jpg_image_buffer.close()
|
101
|
+
return array
|
102
|
+
```
|
103
|
+
と書きました。
|
104
|
+
print(results)ではdateの新しいもの順に<QuerySet [<TestAndUser: xxx 59>, <TestAndUser: xxx 58>, <TestAndUser: xxx 54>, <TestAndUser: xxx 52>, <TestAndUser: xxx 50>, <TestAndUser: kadena xxx>]> と表示されました。
|