Пример #1
0
def main(from_java_string):
	fj_string = from_java_string
	group_id_start = len('group_id=')
	group_id_start += 1
	group_id_end = fj_string.find(',')
	group_id = fj_string[group_id_start:group_id_end]
	item_id_start = fj_string.find('item_id')
	item_id_start += len('item_id')
	item_id_start += 1
	item_id = fj_string[item_id_start:-1]
	print (group_id + item_id, flush=True)
	#items = []
	to_jikkyolizer_data = JikkyolizerAccess()
	#if item_id is None:  #false
	if isinstance(item_id, str):
		dummy = 'aaa'
	else:
		dummy = 'ccc'
	#if group_id is None:   #false
	if isinstance(group_id, str):
		dummy2 = 'bbb'
	else:
		dummy2 = 'ddd'

	try:
		to_jikkyolizer_data.dict_insert('sox_jikkyolized',{ 'group_id':group_id, 'item_id':item_id, 'total_number':0 }) 
	except:
		#f.write('group_id=' + group_id + ', item_id=' +item_id +  '\n')
		#f.flush()
		pass
	return item_id, str(type(item_id))
Пример #2
0
def main(from_jikkyolizer_string):
    group_id, item_id, raw_value, row_timestamp = parse_arg(
        from_jikkyolizer_string)
    if judge_item_kind(raw_value) == float:
        raw_value = '{0:4.4g}'.format(raw_value)
    to_outer = [group_id, item_id, raw_value, row_timestamp]
    to_jikkyolizer_data = JikkyolizerAccess()
    to_jikkyolizer_data.dict_insert(
        'sox_data', {
            'group_id': group_id,
            'item_id': item_id,
            'raw_value': raw_value,
            'row_timestamp': row_timestamp
        })
    jikkyolize_flag = insert_jikkyolized(item_id, group_id, raw_value,
                                         row_timestamp, to_jikkyolizer_data)
    last_change = insert_last_data(item_id, group_id, raw_value, row_timestamp,
                                   to_jikkyolizer_data)
    raw_ok, last_ok, jikkyolized_ok = check_too_past(to_jikkyolizer_data)
    item_blacklist = [
        'longitude', 'latitude', 'url', 'address', '運行状況', '遅延時配信日時', 'image',
        'URL', 'TEL'
    ]
    if item_id in item_blacklist:
        return 0
    raw_value_blacklist = ['', '-']
    if raw_value == raw_value_blacklist or len(raw_value) > 200:
        return 0
    #raw_ok, last_ok, jikkyolized_ok = number_voices(to_jikkyolizer_data)

    SearchRelation(to_outer)

    jikkyolized = 0
    if jikkyolized_ok == 1:
        if jikkyolize_flag == 'upper_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'upper_jikkyolized', 2, last_change)
            jikkyolized = 1
        elif jikkyolize_flag == 'lower_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'lower_jikkyolized', 2, last_change)
            jikkyolized = 1
        elif jikkyolize_flag == 'max_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'max_jikkyolized', 1, last_change)
            jikkyolized = 1
        elif jikkyolize_flag == 'min_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'min_jikkyolized', 1, last_change)
            jikkyolized = 1
    if last_ok == 1 and jikkyolized == 0 and last_change == 1:
        JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                            'last_changed', 3, last_change)
        jikkyolized = 1
    if raw_ok == 1 and jikkyolized == 0:
        JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                            'raw_data', 4, last_change)
        jikkyolized = 1
Пример #3
0
def main(from_jikkyolizer_string):
    group_id, item_id, raw_value, row_timestamp = parse_arg(
        from_jikkyolizer_string)
    to_jikkyolizer_data = JikkyolizerAccess()
    to_jikkyolizer_data.dict_insert(
        'sox_data', {
            'group_id': group_id,
            'item_id': item_id,
            'raw_value': raw_value,
            'row_timestamp': row_timestamp
        })
    insert_jikkyolized(item_id, group_id, raw_value, row_timestamp,
                       to_jikkyolizer_data)
class SearchRelation():
    def __init__(self):
        self.relation_access = JikkyolizerAccess()

    def add_relation(self, group_or_item, relation_name):
        self.relation_access.dict_update('sox_jikkyolized',
                                         {group_or_item: relation_name}, {
                                             'group_id': group_id,
                                             'item_id': item_id
                                         })

    def fetch_relation(self, relation_name, group_or_item, except_group,
                       except_item, raw_value):
        rel_flag = 'No_speciality'
        if group_or_item == 'group':
            rels = self.relation_access.dict_select(
                'sox_jikkyolized', {'group_relation': relation_name})
        if group_or_item == 'item':
            rels = self.relation_access.dict_select(
                'sox_jikkyolized', {'item_relation': relation_name})
        rel_graph = []
        smaller = 0
        for rel in rels:
            if rel['group_id'] != except_group or rel['item_id'] != except_item:
                rel_es = self.relation_access.dict_select(
                    'sox_data_last', {
                        'group_id': rel['group_id'],
                        'item_id': rel['item_id']
                    })
                for rel_e in rel_es:
                    if rel['item_kind'] is not None:
                        item_kind = rel['item_kind']
                        rel_graph.append(eval(item_kind)(rel_e['raw_value']))
                        e_value = eval(item_kind)(rel_e['raw_value'])
                        if e_value < raw_value:
                            smaller += 1

        if item_kind == 'int' or item_kind == 'float':
            max_value = max(rel_graph)
            min_value = min(rel_graph)
            if raw_value > max_value:
                rel_flag = 'rel_max'
            elif raw_value < min_value:
                rel_flag = 'rel_min'
            elif (smaller / len(rel_graph)) < 0.1:
                rel_flag = 'rel_little'
            elif (smaller / len(rel_graph)) > 0.9:
                rel_flag = 'rel_much'

        return rel_flag
class JikkyolizerAnalyze(object):
	def __init__(self, group_id = None, item_id = None):
		self.ja = JikkyolizerAccess()
		self.group_id = group_id
		self.item_id = item_id
		self.search_sessions = ['week', 'month', 'year']

	def flexible_detect_group_id(func):
		if group_id is None:
			if self.group_id is not None:
				group_id = self.group_id
				item_id = self.item_id
			else:
				raise 'group_id is not detected'
		func(self)
		return wrapper
		
	@flexible_detect_group_id
	def get_past_item_session(self, session_from, session_to, group_id = None, item_id = None):
		where_sql = 'where group_id=' + group_id + ' and item_id=' + item_id + ' row_timestamp>' + session_from + 'and row_timestamp<' + 'session_to'
		return self.ja.raw_select('sox_data', ['raw_value', 'row_timestamp'], where_sql)

	def calc_past_item_average(self, general_history):
		value_history_total = 0.0
		number_of_history = 0
		for gh in general_history:
			value_history_total += float(gh['raw_value'])
			number_of_history += 1
		return value_history_total / number_of_history 
			
	@flexible_detect_group_id
	def calc_average_value(self, group_id = None, item_id = None):
		now = datetime.datetime.now()
		search_sessions = ['week', 'month', 'year']
		search_trend = ['increase', 'decrease']
		data = {}
		for ss in self.search_sessions:
			data[ss] = {}
			for st in search_trend:
				data[ss][st] = True
			
		for i in range(4):
			for ss in search_sessions:
				data[ss][i] = { 'history' : [], 'session_from' : None, 'session_to' : None }
				data[ss][i]['session_from'] = now - relativedelta(eval(ss + 's') = i)
				data[ss][i]['session_to'] = session_from - relativedelta(eval(ss + 's') = 1)
				data[ss][i]['history'] = self.get_past_item_session(group_id, item_id, data[ss][i]['session_from'], data[ss][i]['session_to'])
				data[ss][i]['average'] = self.calc_past_item_average(data[ss][i]['history'])
			if i > 0:
				if data[ss][i]['average'] >= data[ss][i - 1]['average']:
					data[ss]['decrease'] = False
				if data[ss][i]['average'] <= data[ss][i - 1]['average']:
					data[ss]['increase'] = False

		return data
Пример #6
0
def fetch_new_voice(past_voices):
    to_voice_data = JikkyolizerAccess()
    sql = 'select * from voice_prior order by vocalize_prior asc, insert_timestamp desc;'
    to_voice_data.cursor.execute(sql)
    voice_priority = to_voice_data.cursor.fetchall()
    for voice_pri in voice_priority:
        if '{0:07d}'.format(voice_pri['ID']) in past_voices.values():
            pass
        else:
            return voice_pri['ID']
    return 0
def main(from_java_string):
    fj_string = from_java_string
    group_id_start = len('group_id=')
    group_id_start += 1
    group_id_end = fj_string.find(',')
    group_id = fj_string[group_id_start:group_id_end]
    item_id_start = fj_string.find('item_id')
    item_id_start += len('item_id')
    item_id_start += 1
    item_id_end = fj_string.find(',')
    item_id = fj_string[item_id_start:item_id_end]
    #item_id = fj_string[item_id_start:-1]
    group_name_start = fj_string.find('group_name')
    group_name_start += len('group_name')
    group_name_start += 1
    group_name = fj_string[group_name:-1]
    print(group_id + item_id + group_name, flush=True)
    #items = []
    to_jikkyolizer_data = JikkyolizerAccess()
    #if item_id is None:  #false
    if isinstance(item_id, str):
        dummy = 'aaa'
    else:
        dummy = 'ccc'
    #if group_id is None:   #false
    if isinstance(group_id, str):
        dummy2 = 'bbb'
    else:
        dummy2 = 'ddd'

    try:
        to_jikkyolizer_data.dict_insert('sox_jikkyolized', {
            'group_id': group_id,
            'item_id': item_id,
            'total_number': 0
        })
    except:
        #f.write('group_id=' + group_id + ', item_id=' +item_id +  '\n')
        #f.flush()
        pass
    pre_ID = to_jikkyolizer_data.dict_select('sox_jikkyolized', {
        'group_id': group_id,
        'item_id': item_id
    })
    voice_ID = '{0:07d}'.format(pre_ID[0]['ID'])
    pre_ID = to_jikkyolizer_data.dict_insert('sox_id_name_relation', {
        'device_id': group_id,
        'device_name': item_id
    })
    MakeVoice.raw_vocalize(group_name + 'の' + item_id, 'group_item',
                           'id-' + voice_ID)
    return item_id, str(type(item_id))
Пример #8
0
def ex_main():
	to_jikkyolizer_data = JikkyolizerAccess()
	to_jikkyolizer_data.dict_insert('sox_jikkyolized',{ 'group_id':'"123"', 'item_id':'ううう' })
Пример #9
0
    def __init__(self, item_id, group_id, raw_value, row_timestamp, reason,
                 vocalize_prior, is_change, rel_flag, relations):
        to_vocalize_data = JikkyolizerAccess()
        sql = 'SELECT auto_increment FROM information_schema.tables WHERE table_name = "voice_prior";'
        to_vocalize_data.cursor.execute(sql)
        jikkyo_id_pre = to_vocalize_data.cursor.fetchone()
        jikkyo_id = jikkyo_id_pre['auto_increment']
        voice_prior_dicts = {
            'vocalize_kind': reason,
            'vocalize_prior': vocalize_prior,
            'group_id': group_id,
            'item_id': item_id,
            'raw_value': raw_value,
            'row_timestamp': row_timestamp,
            'relation_reason': rel_flag,
            'voice_0': 1,
            'voice_1': 1,
            'voice_2': 1,
            'voice_3': 1,
            'voice_4': 1,
            'voice_5': 0,
            'voice_6': 0,
            'voice_7': 0
        }
        if reason == 'raw_data' and reason == 'last_changed':
            pass
        elif reason == 'upper_jikkyolized' or reason == 'lower_jikkyolized' or reason == 'max_jikkyolized' or reason == 'min_jikkyolized':
            voice_prior_dicts['voice_5'] = 1

        if rel_flag != 'No_relation' and rel_flag != 'No_speciality':
            voice_prior_dicts['voice_6'] = 1
            voice_prior_dicts['voice_7'] = 1

        to_vocalize_data.dict_insert('voice_prior', voice_prior_dicts)
        voice_prior_dicts['ID'] = jikkyo_id
        to_vocalize_data.dict_insert('voice_prior_record', voice_prior_dicts)
        jikkyo_id7 = '{0:07d}'.format(jikkyo_id)

        how_ago = int(time.mktime(datetime.now().timetuple())) - int(
            datetime.strptime(row_timestamp,
                              '%Y-%m-%d %H:%M:%S').strftime('%s'))
        how_ago_second = how_ago % 60
        how_ago_minute = int(how_ago % 3600 / 60)
        how_ago_hour = int(how_ago % 86400 / 3600)
        vocalize_sentence = '今から'
        if how_ago_minute < 1:
            vocalize_sentence += str(how_ago_second) + '秒まえ、'
        elif how_ago_minute >= 1 and how_ago_hour < 1:
            vocalize_sentence += str(how_ago_minute) + '分まえ、'
        else:
            vocalize_sentence += str(how_ago_hour) + '時間まえ、'

        cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-0.wav'
        subprocess.call(cmd, shell=True)

        vocalize_sentence = group_id + 'の' + item_id

        cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-1.wav'
        subprocess.call(cmd, shell=True)

        vocalize_sentence = 'の値が'
        cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-2.wav'
        subprocess.call(cmd, shell=True)

        vocalize_sentence = str(raw_value)
        cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-3.wav'
        subprocess.call(cmd, shell=True)

        if is_change == 1:
            vocalize_sentence = 'になりました。'
        else:
            vocalize_sentence = 'を示しました。'
        cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-4.wav'
        subprocess.call(cmd, shell=True)

        if reason == 'upper_jikkyolized':
            vocalize_sentence = 'これはとても高い値です。'
            cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-5.wav'
            subprocess.call(cmd, shell=True)
        elif reason == 'lower_jikkyolized':
            vocalize_sentence = 'これはとても低い値です。'
            cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-5.wav'
            subprocess.call(cmd, shell=True)
        elif reason == 'max_jikkyolized':
            vocalize_sentence = 'これは今までで最高の値です。'
            cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-5.wav'
            subprocess.call(cmd, shell=True)
        elif reason == 'min_jikkyolized':
            vocalize_sentence = 'これは今までで最低の値です。'
            cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-5.wav'
            subprocess.call(cmd, shell=True)

        if rel_flag != 'No_relation' and rel_flag != 'No_speciality':
            vocalize_sentence = 'なお、同種類の' + relations + 'の値の中で'
            cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-6.wav'
            subprocess.call(cmd, shell=True)
            if rel_flag == 'rel_max':
                vocalize_sentence = '最高の値を示しています。'
                cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-7.wav'
                subprocess.call(cmd, shell=True)
            if rel_flag == 'rel_min':
                vocalize_sentence = '最低の値を示しています。'
                cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-7.wav'
                subprocess.call(cmd, shell=True)
            if rel_flag == 'rel_much':
                vocalize_sentence = 'とても高い値を示しています。'
                cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-7.wav'
                subprocess.call(cmd, shell=True)
            if rel_flag == 'rel_little':
                vocalize_sentence = 'とても低い値を示しています。'
                cmd = 'curl "https://api.voicetext.jp/v1/tts" -u "mpbw1hnrp32pdde7:" -d "text= \'' + vocalize_sentence + '\'" -d "speaker=hikari" -d "speed=100" -d "pitch=100" -d "volume=100" -o /var/www/html/voices/jikkyo-' + jikkyo_id7 + '-7.wav'
                subprocess.call(cmd, shell=True)
	def __init__(self, group_id = None, item_id = None):
		self.ja = JikkyolizerAccess()
		self.group_id = group_id
		self.item_id = item_id
		self.search_sessions = ['week', 'month', 'year']
 def __init__(self):
     self.relation_access = JikkyolizerAccess()
def main(from_jikkyolizer_string):
    group_id, item_id, raw_value, row_timestamp = parse_arg(
        from_jikkyolizer_string)
    d_time = datetime.strptime(
        row_timestamp,
        '%Y-%m-%d %H:%M:%S')  # + timedelta(minutes=21)   #この部分、ワンチャン直った?
    row_timestamp = d_time.strftime('%Y-%m-%d %H:%M:%S')
    if judge_item_kind(raw_value) == float:
        raw_value = '{0:4.4g}'.format(raw_value)
    to_jikkyolizer_data = JikkyolizerAccess()
    to_jikkyolizer_data.dict_insert(
        'sox_data', {
            'group_id': group_id,
            'item_id': item_id,
            'raw_value': raw_value,
            'row_timestamp': row_timestamp
        })
    jikkyolize_flag, rel_flag, relations = insert_jikkyolized(
        item_id, group_id, raw_value, row_timestamp, to_jikkyolizer_data)
    last_change = insert_last_data(item_id, group_id, raw_value, row_timestamp,
                                   to_jikkyolizer_data)
    raw_ok, last_ok, jikkyolized_ok = check_too_past(to_jikkyolizer_data)
    item_blacklist = [
        'longitude', 'latitude', 'url', 'address', '運行状況', '遅延時配信日時', 'image',
        'URL', 'TEL', 'ジャンル', '住所', '交通手段', '営業時間'
    ]
    if item_id in item_blacklist:
        return 0
    raw_value_blacklist = ['', '-']
    if raw_value == raw_value_blacklist or len(raw_value) > 200:
        return 0
    #raw_ok, last_ok, jikkyolized_ok = number_voices(to_jikkyolizer_data)
    jikkyolized = 0
    if jikkyolized_ok == 1:
        if jikkyolize_flag == 'upper_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'upper_jikkyolized', 2, last_change, rel_flag,
                                relations)
            jikkyolized = 1
        elif jikkyolize_flag == 'lower_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'lower_jikkyolized', 2, last_change, rel_flag,
                                relations)
            jikkyolized = 1
        elif jikkyolize_flag == 'max_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'max_jikkyolized', 1, last_change, rel_flag,
                                relations)
            jikkyolized = 1
        elif jikkyolize_flag == 'min_jikkyolized':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'min_jikkyolized', 1, last_change, rel_flag,
                                relations)
            jikkyolized = 1
        elif relations == 'rel_max' or relations == 'rel_min' or relations == 'rel_little' or relations == 'rel_much':
            JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                                'raw_data', 2, last_change, rel_flag,
                                relations)
            return 0

    if last_ok == 1 and jikkyolized == 0 and last_change == 1:
        JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                            'last_changed', 3, last_change, rel_flag,
                            relations)
        jikkyolized = 1
    if raw_ok == 1 and jikkyolized == 0:
        JikkyolizerVocalize(item_id, group_id, raw_value, row_timestamp,
                            'raw_data', 4, last_change, rel_flag, relations)
        jikkyolized = 1