示例#1
0
def find_nearest_time(look_for, target_list):
    # 格式化查询数据
    look_for = time2secs(format_time(look_for))
    target_list = [
        time2secs(format_time(each_item)) for each_item in target_list
    ]
    return (secs2time(find_closest(look_for, target_list)))
示例#2
0
    'Marathon'
]
hello_msg = "Welcome to the Marathon Club's App"
quit_msg = "Quitting the Marathon Club's App."

row_data = {}

with open('/sdcard/sl4a/scripts/PaceData.csv') as paces:
    column_headings = paces.readline().strip().split(',')
    column_headings.pop(0)
    for each_line in paces:
        row = each_line.strip().split(',')
        row_label = row.pop(0)
        inner_dict = {}
        for i in range(len(column_headings)):
            inner_dict[format_time(row[i])] = column_headings[i]
        row_data[row_label] = inner_dict

app = android.Android()


def status_update(msg, how_long=2):
    app.makeToast(msg)
    time.sleep(how_long)


def do_dialog(title, data, func, ok='Select', notok='Quit'):
    app.dialogCreateAlert(title)
    func(data)
    app.dialogSetPositiveButtonText(ok)
    if notok:
示例#3
0
文件: last.py 项目: azych/python_head
	target_data = [time2secs(t) for t in target_data]
	return(secs2time(find_closest(look_for, target_data)))


data_dict = {}

with open('PaceData.csv') as pacedata:
	headings_list = pacedata.readline().strip().split(',')
	headings_list.pop(0)

	for each_line in pacedata:
		row_data = each_line.strip().split(',')
		row_name = row_data.pop(0)
		inner_dict = {}
		for i in range(len(headings_list)):
			inner_dict[format_time(row_data[i])] = headings_list[i]
		data_dict[row_name] = inner_dict


distance_run = input('Enter the distance attempted: ')
recorded_time = input('Enter the recorded time: ')
predicted_distance = input('Enter the distance you want a prediction for: ')

closest_time = find_nearest_time(format_time(recorded_time), data_dict[distance_run])
closest_column_heading = data_dict[distance_run][closest_time]

prediction = [k for k in data_dict[predicted_distance].keys() 
			if data_dict[predicted_distance][k] == closest_column_heading]

print('The predicted time running ' + predicted_distance + ' is: ' + prediction[0] + '.')
示例#4
0
# 定义字典信息
row_data = {}
# 获取个数据
with open("PaceData.csv") as paces:
    # 先获取标题
    column_headings = paces.readline().strip().split(",")
    # 去掉第一个数据
    column_headings.pop(0)
    # 循环获取数据
    for each_line in paces:
        row = each_line.strip().split(",")
        row_label = row.pop(0)
        # 定义内部字典
        inner_dict = {}
        for i in range(len(row)):
            inner_dict[tm2secs2tm.format_time(row[i])] = column_headings[i]
        # 将数据与列标题关联
        row_data[row_label] = inner_dict

# 提示数据输入
distance_run = input("Enter the distance attempted:")
recorded_time = input("Enter the recorded time:")
predicted_distance = input("Enter the distance you want a prediction for:")

closest_time = find_nearest_time(recorded_time, row_data[distance_run])
closest_column_heading = row_data[distance_run][closest_time]
prediction = [
    k for k in row_data[predicted_distance].keys()
    if row_data[predicted_distance][k] == closest_column_heading
]
示例#5
0
                '13.1mi', '25k', '30k', 'Marathon' ]
hello_msg = "Welcome to the Marathon Club's App"
quit_msg = "Quitting the Marathon Club's App."

row_data = {}

with open('/sdcard/sl4a/scripts/PaceData.csv') as paces:
    #打开一个特定文件夹,得到并预处理CVS数据
    column_headings = paces.readline().strip().split(',')
    column_headings.pop(0)
    for each_line in paces:
        row = each_line.strip().split(',')
        row_label = row.pop(0)
        inner_dict = {}
        for i in range(len(column_headings)):
            inner_dict[format_time(row[i])] = column_headings[i]
        row_data[row_label] = inner_dict

app = android.Android()
#创建android应用对象,并包含你的辅助函数
def status_update(msg, how_long=2):
    app.makeToast(msg)
    time.sleep(how_long)

def do_dialog(title, data, func, ok='Select', notok='Quit'):
    app.dialogCreateAlert(title)
    func(data)
    app.dialogSetPositiveButtonText(ok)
    if notok:
        app.dialogSetNegativeButtonText(notok)
    app.dialogShow()
示例#6
0
distances = ['2mi', '5k', '5mi', '10k', '15k', '10mi', '20k', '13.1mi', '25k', '30k', 'Marathon']
hello_msg = "Welcome to the Marathon Club's App"
quit_msg = "Quitting the Marathon Club's App."
row_data = {}

with open('PaceData.csv') as paces:
	column_headings = paces.readline().strip().split(',')
	column_headings.pop(0)
	
	for each_line in paces:
		row = each_line.strip().split(',')
		row_label = row.pop(0)
		inner_dict = {}
		for i in range(len(column_headings)):
			inner_dict[format_time(row[i])] = column_headings[i]	# associate the column heading with the time value from the row
		row_data[row_label] = inner_dict
		

app = android.Android()
status_update(hello_msg)

resp = do_dialog("Pick a distance", distances, app.dialogSetSingleChoiceItems)
if resp['which'] in ('positive'):
	distance_run = app.dialogGetSelectedItems().result[0]
	distance_run = distances[distance_run]
	recorded_time = app.dialogGetInput("Enter a " + distance_run + " time:", "Use HH:MM:SS format:").result
	closest_time = find_nearest_time(format_time(recorded_time), row_data[distance_run])
	closest_column_heading = row_data[distance_run][closest_time]
	resp = do_dialog("Pick a distance to predict", distances, app.dialogSetSingleChoiceItems)
	if resp['which'] in ('positive'):
示例#7
0
    where = [time2secs(t) for t in target_data]
    res = find_closest(what, where)
    return(secs2time(res))

row_data = {}

with open('PaceData.csv') as paces:

    column_headings = paces.readline().strip().split(',')
    column_headings.pop(0)

    for each_line in paces:
        row = each_line.strip().split(',')
        row_label = row.pop(0)
        inner_dict = {}
        for i in range(len(column_headings)):
            inner_dict[format_time(row[i])] = column_headings[i]
        row_data[row_label] = inner_dict

distance_run = eval(input('Enter the distance attempted: '))
recorded_time = eval(input('Enter the recorded time: '))
predicted_distance = eval(input('Enter the distance you want a prediction for: '))

closest_time = find_nearest_time(format_time(recorded_time), row_data[distance_run])
closest_column_heading = row_data[distance_run][closest_time]

prediction = [k for k in list(row_data[predicted_distance].keys())
                  if row_data[predicted_distance][k] == closest_column_heading]

print(('The predicted time running ' + predicted_distance + ' is: ' + prediction[0] + '.'))
示例#8
0
import time
from tm2secs2tm import format_time
row_data = {}
with open("data/PaceData.csv") as paces:

    column_headings = paces.readline().strip().split(",")
    column_headings.pop(0)

    for each_line in paces:
        row = each_line.strip() .split(",")
        row_label = row.pop(0)
        inner_data = {}
        for each_column in column_headings:
            #inner_data[each_column] = row.pop(0)
            inner_data[format_time(row.pop(0))] = each_column
        row_data[row_label] = inner_data

from find_it import find_closest
from tm2secs2tm import time2secs, secs2time

def find_nearest_time(look_for, target_data):
    look_for_value = time2secs(look_for)
    where_to_find = [time2secs(t) for t in target_data]
    target_value = find_closest(look_for_value, where_to_find)
    return secs2time(target_value)

distance_run = "20k"#input("Enter the distance attempted: ")
recorded_time = "59:59"#input("Enter the recorded time: ")
predicted_distance = "Marathon"#input("Enter the distance you want a prediction for: ")

closest_time = find_nearest_time(format_time(recorded_time), row_data[distance_run])