• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ishikota / kyoka / 20

24 Oct 2016 - 5:58 coverage: 92.529% (+2.5%) from 90.06%
20

Pull #16

travis-ci

web-flow
Update sample script to use new save logic
Pull Request #16: Change save logic

116 of 122 new or added lines in 8 files covered. (95.08%)

1 existing line in 1 file now uncovered.

644 of 696 relevant lines covered (92.53%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/kyoka/value_function/base_table_action_value_function.py
1
from kyoka.value_function.base_action_value_function import BaseActionValueFunction
1×
2
import os
1×
3
import pickle
1×
4

5
class BaseTableActionValueFunction(BaseActionValueFunction):
1×
6

7
  SAVE_FILE_NAME = "table_action_value_function_data.pickle"
1×
8

9
  def setUp(self):
1×
10
    self.table = self.generate_initial_table()
1×
11

12
  def calculate_value(self, state, action):
1×
13
    return self.fetch_value_from_table(self.table, state, action)
1×
14

15
  def update_function(self, state, action, new_value):
1×
16
    self.update_table(self.table, state, action, new_value)
1×
17

18
  def save(self, save_dir_path):
1×
19
    file_path = os.path.join(save_dir_path, self.SAVE_FILE_NAME)
1×
20
    self.__pickle_data(file_path, self.table)
1×
21

22
  def load(self, load_dir_path):
1×
23
    file_path = os.path.join(load_dir_path, self.SAVE_FILE_NAME)
1×
24
    if not os.path.exists(file_path):
1×
25
      raise IOError('The saved data of "TableActionValueFunction" is not found on [ %s ]'% load_dir_path)
1×
26
    self.table = self.__unpickle_data(file_path)
1×
27

28
  def generate_initial_table(self):
1×
29
    err_msg = self.__build_err_msg("generate_initial_table")
!
30
    raise NotImplementedError(err_msg)
!
31

32
  def fetch_value_from_table(self, table, state, action):
1×
33
    err_msg = self.__build_err_msg("fetch_value_from_table")
!
34
    raise NotImplementedError(err_msg)
!
35

36
  def update_table(self, table, state, action, new_value):
1×
37
    err_msg = self.__build_err_msg("update_table")
!
38
    raise NotImplementedError(err_msg)
!
39

40

41
  def __gen_save_file_path(self, base_dir_path):
1×
NEW
42
    return os.path.join(base_dir_path, self.SAVE_FILE_NAME)
!
43

44
  def __pickle_data(self, file_path, data):
1×
45
    with open(file_path, "wb") as f:
1×
46
      pickle.dump(data, f)
1×
47

48
  def __unpickle_data(self, file_path):
1×
49
    with open(file_path, "rb") as f:
1×
50
      return pickle.load(f)
1×
51

52
  def __build_err_msg(self, msg):
1×
53
    base_msg = "[ {0} ] class does not implement [ {1} ] method"
!
54
    return base_msg.format(self.__class__.__name__, msg)
!
55

Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc