def test_from_string_customized(): i1, i2, i3, i4 = '<"0"-"1">', '<!"0"-"1">', '<"0"-"1"!>', '<!"0"-"1"!>' params = { 'conv': lambda s: int(s[1:-1]), 'disj': ' or ', 'sep': '-', 'left_open': '<!', 'left_closed': '<', 'right_open': '!>', 'right_closed': '>', 'pinf': r'\+oo', 'ninf': '-oo', } assert I.from_string(i1, **params) == I.closed(0, 1) assert I.from_string(i2, **params) == I.openclosed(0, 1) assert I.from_string(i3, **params) == I.closedopen(0, 1) assert I.from_string(i4, **params) == I.open(0, 1) assert I.from_string('<!!>', **params) == I.empty() assert I.from_string('<"1">', **params) == I.singleton(1) assert I.from_string('<!-oo-"1">', **params) == I.openclosed(-I.inf, 1) assert I.from_string('<"1"-+oo!>', **params) == I.closedopen(1, I.inf) assert I.from_string('<"0"-"1"> or <"2"-"3">', **params) == I.closed(0, 1) | I.closed(2, 3)
def test_from_string(): i1, i2, i3, i4 = '[0,1]', '(0,1]', '[0,1)', '(0,1)' assert I.from_string(i1, int) == I.closed(0, 1) assert I.from_string(i2, int) == I.openclosed(0, 1) assert I.from_string(i3, int) == I.closedopen(0, 1) assert I.from_string(i4, int) == I.open(0, 1) assert I.from_string('()', int) == I.empty() assert I.from_string('[1]', int) == I.singleton(1) assert I.from_string('[0,1] | [2,3]', int) == I.closed(0, 1) | I.closed(2, 3) with pytest.raises(Exception): I.from_string('[1,2]', None)
def load_row(self, ws, row): item = {} for index_col in range(0, ws.ncols): if index_col == 0: # id item['id'] = ws.cell(row, index_col).value elif index_col == 1: # 接口名称 item['name'] = ws.cell(row, index_col).value elif index_col == 2: # 接口英文名称 item['name_en'] = ws.cell(row, index_col).value elif index_col == 3: # 调用方法 item['operation'] = ws.cell(row, index_col).value elif index_col == 4: # 超时 item['overtime'] = ws.cell(row, index_col).value elif index_col == 5: # 接口URL item['url'] = ws.cell(row, index_col).value elif index_col == 6: # 参数 arg_dict = {} arg_value = ws.cell(row, index_col).value arg_value = ''.join(arg_value.split()) arg_list = arg_value.split(',') for i in range(0, len(arg_list)): temp_list = arg_list[i].split('=') if len(temp_list) > 1: # arg_values = temp_list[1].split('/') # arg_dict[temp_list[0]] = arg_values arg_dict[temp_list[0]] = temp_list[1] else: arg_dict[temp_list[0]] = '' item['arg_dict'] = arg_dict elif index_col == 7: # 开始时间偏移量 item['begin_offset'] = ws.cell(row, index_col).value elif index_col == 8: # 结束时间偏移量 item['end_offset'] = ws.cell(row, index_col).value elif index_col == 9: # 参数范围 range_item = ws.cell(row, index_col).value range_dict = {} if range_item: # 按分号分开成几部分 range_list = range_item.split(';') for i in range(0, len(range_list)): # 每部分内部再按照冒号分开 range_temp = range_list[i].split(':') if len(range_temp) > 1: srange = ''.join(range_temp[1].split()) if srange[0] == '{': range_dict[range_temp[0]] = self.load_str_range(srange) elif srange[0] == '[' or srange[0] == '(': range_dict[range_temp[0]] = intervals.from_string(srange, float) else: range_dict[range_temp[0]] = '' item['range_dict'] = range_dict if item: item['module'] = ws.name return item
def initialize_time_intervals(): try: with open('TimeFinder.data', 'r') as file: raw_string = file.read() string_dict = ast.literal_eval(raw_string) converter = lambda s: datetime.strptime(s, '%H:%M').time() for name, string_interval in string_dict.items(): time_intervals[name] = I.from_string(string_interval, conv = converter) except: guild = discord.utils.get(bot.guilds, name=GUILD) for member in guild.members: if not member.bot: time_intervals[member.name] = I.empty()
def check(self, config_value, input_value): result = intervals.from_string(config_value, conv=float).contains(input_value) print("check: {}, {}, {}".format(config_value, input_value, result)) return result
def convertMappingFromString(mapping): new_mapping = {} for iv_old, iv_news in mapping.items(): new_mapping[I.from_string(iv_old, conv=int)] =\ IntervalHelper.getIntervalsFromString(iv_news) return new_mapping
def getIntervalFromString(string): return I.from_string(str(string), conv=int)
def getIntervalsFromString(string_intervals): intervals = [] for s in string_intervals: intervals.append(I.from_string(str(s), conv=int)) return intervals