from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants # import csv # csvファイルの読み書きに必要,自分で書き足すこと # import pandas as pd # import json class Introduction(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( num_rounds=self.session.config['num_rounds'], ) class ResultsWaitPage1(WaitPage): after_all_players_arrive = 'update' class Input1(Page): form_model = 'player' form_fields = ['cut_input'] def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return dict( num_trees=Constants.num_trees, image_path1 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree1), image_path2 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree2), image_path3 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree3), image_path4 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree4), ) class Input2(Page): form_model = 'player' form_fields = ['cut_input'] timeout_seconds = 60 def is_displayed(self): return self.round_number > 1 def vars_for_template(self): ## 配列の作成に必要な定数をローカルに作成 round_number = self.round_number # 現在のラウンド数 players = self.group.get_players() # すべてのプレイヤーのリスト num_players = Constants.players_per_group # プレイヤーの人数 return dict( round_number = self.round_number, num_trees = Constants.num_trees, cut_input_prev = self.player.in_round(self.round_number-1).cut_input, cut_modify_prev = self.player.in_round(self.round_number-1).cut_modify, point_get_prev = self.player.in_round(self.round_number-1).point_get, point_accumulation_prev = self.player.in_round(self.round_number-1).point_accumulation, image_path1 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree1), image_path2 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree2), image_path3 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree3), image_path4 = 'STY1985/tree_{}.jpg'.format(self.group.size_tree4), ) def js_vars(self): ## 配列の作成に必要な定数をローカルに作成 round_number = self.round_number # 現在のラウンド数 players = self.group.get_players() # すべてのプレイヤーのリスト num_players = Constants.players_per_group # プレイヤーの人数 ## point_accumulation を出力する List を作成 List_point_accumulation = [] for p in players: # リストに含まれるプレイヤーについて id = p.id_in_group # id を取得 pname = 'Player' + str(id) # プレイヤー名の文字列 pdata = [] # データ格納用のリスト for j in range(round_number-1): # 1ラウンド目から直前のラウンドまでについて pdata.append(p.in_round(j+1).point_accumulation) # pdata リストに値を追加 pdict = {'name':pname,'data':pdata} # プレイヤー毎のリストを作成 List_point_accumulation.append(pdict) print('List_point_accumulation is', List_point_accumulation) # デバッグ用 return dict( round_number = self.round_number, num_rounds = self.session.config['num_rounds'], # num_rounds=Constants.num_rounds, List_point_accumulation = List_point_accumulation, ) class ResultsWaitPage2(WaitPage): after_all_players_arrive = 'solve' class GameOver(Page): def is_displayed(self): # return self.round_number == Constants.num_rounds return self.round_number == self.session.config['num_rounds'] def vars_for_template(self): ## 配列の作成に必要な定数をローカルに作成 round_number = self.round_number # 現在のラウンド数 players = self.group.get_players() # すべてのプレイヤーのリスト num_players = Constants.players_per_group # プレイヤーの人数 return dict( round_number = self.round_number, num_trees=Constants.num_trees, cut_input = self.player.cut_input, cut_modify = self.player.cut_modify, point_get = self.player.point_get, point_accumulation = self.player.point_accumulation, ) def js_vars(self): ## 配列の作成に必要な定数をローカルに作成 round_number = self.round_number # 現在のラウンド数 players = self.group.get_players() # すべてのプレイヤーのリスト num_players = Constants.players_per_group # プレイヤーの人数 ## point_accumulation を出力する List を作成 List_point_accumulation = [] for p in players: # リストに含まれるプレイヤーについて id = p.id_in_group # id を取得 pname = 'Player' + str(id) # プレイヤー名の文字列 pdata = [] # データ格納用のリスト for j in range(round_number-1): # 1ラウンド目から直前のラウンドまでについて pdata.append(p.in_round(j+1).point_accumulation) # pdata リストに値を追加 pdata.append(p.point_accumulation) # 最終ラウンドの値を追加 pdict = {'name':pname,'data':pdata} # プレイヤー毎のリストを作成 List_point_accumulation.append(pdict) ## num_cut_trees_inputs & _modifyを出力する List を作成 pname1 = '希望' # プレイヤー名の文字列 pdata1 = [] # データ格納用のリスト for j in range(round_number-1): # 1ラウンド目から直前のラウンドまでについて pdata1.append(self.group.in_round(j+1).num_cut_trees_inputs) # pdata リストに値を追加 pdata1.append(self.group.num_cut_trees_inputs) # 最終ラウンドの値を追加 dict1 = {'name':pname1,'data':pdata1} pname2 = '伐採' # プレイヤー名の文字列 pdata2 = [] # データ格納用のリスト for j in range(round_number-1): # 1ラウンド目から直前のラウンドまでについて pdata2.append(self.group.in_round(j+1).num_cut_trees_modify) # pdata リストに値を追加 pdata2.append(self.group.num_cut_trees_modify) # 最終ラウンドの値を追加 dict2 = {'name':pname2,'data':pdata2} List_num_cut_trees = [dict1,dict2] # プレイヤー毎のリストを作成 ## ave_size_of_cut_treesを出力する List を作成 pname1 = 'inputs' # プレイヤー名の文字列 pdata1 = [] # データ格納用のリスト for j in range(round_number-1): # 1ラウンド目から直前のラウンドまでについて pdata1.append(self.group.in_round(j+1).ave_size_of_cut_trees) # pdata リストに値を追加 pdata1.append(self.group.ave_size_of_cut_trees) # 最終ラウンドの値を追加 List_ave_size_of_cut_trees = [{'name':pname1,'data':pdata1}] ## size_tree_averageを出力する List を作成 pname1 = 'inputs' # プレイヤー名の文字列 pdata1 = [] # データ格納用のリスト for j in range(round_number-1): # 1ラウンド目から直前のラウンドまでについて pdata1.append(self.group.in_round(j+1).size_tree_average) # pdata リストに値を追加 pdata1.append(self.group.size_tree_average) # 最終ラウンドの値を追加 List_size_tree_average = [{'name':pname1,'data':pdata1}] print('List_point_accumulation is', List_point_accumulation) # デバッグ用 print('List_num_cut_trees is', List_num_cut_trees) # デバッグ用 print('List_ave_size_of_cut_trees is', List_ave_size_of_cut_trees) # デバッグ用 print('List_size_tree_average is', List_size_tree_average) # デバッグ用 return dict( round_number = self.round_number, num_rounds = self.session.config['num_rounds'], # num_rounds=Constants.num_rounds, List_point_accumulation = List_point_accumulation, List_num_cut_trees = List_num_cut_trees, List_ave_size_of_cut_trees = List_ave_size_of_cut_trees, List_size_tree_average = List_size_tree_average, ) page_sequence = [Introduction, ResultsWaitPage1, Input1, Input2, ResultsWaitPage2, GameOver]