我在做项目时遇到了一些问题。目前我想更新我的csv文件详细信息。在我的csv文件中,有matric id行,类型行,权重行,点行,时间行。
我的问题是,如果同一个用户使用我的程序,用户的详细信息将不会总计。在这种情况下,我想总结我的观点。因此,如果同一用户使用我的项目,用户将知道总分。我是否需要创建另一个函数来调用csv文件中的点值,因此系统将计算总点数,然后将其显示在另一个新行中,即总点数行。请帮帮我谢谢。
这是我的编码。我在Raspberry Pi中使用Python。
打印“Tared ......”
raw_input("put something on:")
name, small, large = open_hid()
print small
nsmall = small / 11000.0 * 100
ntotal = nsmall * 50 #kertas/aluminum/plastik (bonus point)
#merit = ntotal * 0.01
print "Your persentage is:"
print ("%.2f" % nsmall)
print "Your bonus point is:"
print ("%.2f" % ntotal)
with open('sensor2.csv', 'a') as csv_file:
writer = csv.writer(csv_file)
# Write a header row with the name of each column.
writer.writerow(['MatricID', 'Recycle Type', 'Weight', 'Persentage', 'Bonus Points', 'Time'])
# Now loop generating new fake sensor readings every second and writing them
# to the CSV file.
while True:
# Make some fake sensor data.
reading_time = datetime.datetime.now()
matricID = ID
recycleType = option
weight = small
persentage = ("%.2f" % nsmall)
bonusPoint = ("%.2f" % ntotal)
# Print out the data and write to the CSV file.
print('MetricID: {0} Recycle Type: {1} Weight: {2} Persentage: {3} Bonus Points: {4} Time: {5}'.format(matricID, recycleType, weight, persentage, bonusPoint,reading_time))
writer.writerow([matricID, recycleType, weight, persentage, bonusPoint,reading_time])
break
csv_file.close()
elif option == '2':