I am getting data from a CSV file in python for a specific date. Now, I want to get it for a specific time for example from 13:30 to 14:30 for a specific date.
My CSV file look like this:
15 2017/02/07 17:30:45.983
15 2017/02/07 17:30:51.109
16 2017/02/07 17:30:56.008
16 2017/02/07 17:31:01.029
and my current code is like this:
import csv
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showwarning, showinfo
import datetime
import matplotlib.pyplot as plt
#csv_file = csv.reader(open("C:\Users\Lala Rushan\Downloads\ARIF Drop Monitoring Final\ARIF Drop Monitoring Final\DataLog.csv"))
from Tools.scripts.treesync import raw_input
class App(Frame):
def __init__(self, master):
Frame.__init__(self, master)
button1 = Button(self, text="Browse for a file", command=self.askfilename)
button2 = Button(self, text="Count the file", command=self.takedate)
button3 = Button(self, text="Exit", command=master.destroy)
button1.grid()
button2.grid()
button3.grid()
self.userInputFromRaw = Entry(self)
self.userInputFromRaw.grid()
self.userInputToRaw = Entry(self)
self.userInputToRaw.grid()
self.grid()
def askfilename(self):
in_file = askopenfilename()
if not in_file.endswith(('.CSV')):
showwarning('Are you trying to annoy me?', 'How about giving me a CSV file, genius?')
else:
self.in_file=in_file
def CsvImport(self,csv_file):
dist = 0
for row in csv_file:
_dist = row[0]
try:
_dist = float(_dist)
except ValueError:
_dist = 0
dist += _dist
print ("Urine Volume is: %.2f" % (_dist*0.05))
def takedate(self):
from_raw = self.userInputFromRaw.get()
from_date = datetime.date(*map(int, from_raw.split('/')))
print ('From date: = ' + str(from_date))
to_raw = self.userInputToRaw.get()
to_date = datetime.date(*map(int, to_raw.split('/')))
in_file = ("H:\DataLog.csv")
in_file= csv.reader(open(in_file,"r"))
for line in in_file:
_dist = line[0]
try:
file_date = datetime.date(*map(int, line[1].split(' ')[1].split('/')))
if from_date <= file_date <= to_date:
self.CsvImport(in_file)
except IndexError:
pass
root = Tk()
root.title("Urine Measurement")
root.geometry("500x500")
app = App(root)
root.mainloop()
How can I get the data for a specific time and for a specific date?
Use pandas and its DataFrame container, as this is the ideal format for handling data and selecting it. See the example below:
import pandas as pd
df = pd.read_csv('eg.txt', header=None) # Read in the Data.
df.index = [pd.datetime.strptime(i, '%Y/%m/%d%H:%M:%S.%f') for i in (df[1] + df[2])] # Format the time into the index
here
>>> df
0 1 2 3
2017-02-07 17:30:45.983 15 2017/02/07 17:30:45.983 3.3
2017-02-07 17:30:51.109 15 2017/02/07 17:30:51.109 4.4
2017-02-07 17:30:56.008 16 2017/02/07 17:30:56.008 5.2
2017-02-07 17:31:01.029 16 2017/02/07 17:31:01.029 NaN
and you can select a time range you want using:
>>> df[pd.datetime(2017, 2, 7, 17, 30, 50):pd.datetime(2017, 2, 7, 17, 30, 58)] # Slice the wanted time
0 1 2 3
2017-02-07 17:30:51.109 15 2017/02/07 17:30:51.109 4.4
2017-02-07 17:30:56.008 16 2017/02/07 17:30:56.008 5.2
where the csv that generated the data is eg.txt which looks like.
15,2017/02/07,17:30:45.983,3.3
15,2017/02/07,17:30:51.109,4.4
16,2017/02/07,17:30:56.008,5.2
16,2017/02/07,17:31:01.029,NaN
You can then delete, make, move columns and data as you wish.
Related
I connect to an API that provides covid-19 data in Brazil organized by state and city, as follows:
#Bibliotecas
import pandas as pd
from pandas import Series, DataFrame, Panel
import matplotlib.pyplot as plt
from matplotlib.pyplot import plot_date, axis, show, gcf
import numpy as np
from urllib.request import Request, urlopen
import urllib
from http.cookiejar import CookieJar
import numpy as np
from datetime import datetime, timedelta
cj = CookieJar()
url_Bso = "https://brasil.io/api/dataset/covid19/caso_full/data?state=MG&city=Barroso"
req_Bso = urllib.request.Request(url_Bso, None, {"User-Agent": "python-urllib"})
opener_Bso = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
response_Bso = opener_Bso.open(req_Bso)
raw_response_Bso = response_Bso.read()
json_Bso = pd.read_json(raw_response_Bso)
results_Bso = json_Bso['results']
results_Bso = results_Bso.to_dict().values()
df_Bso = pd.DataFrame(results_Bso)
df_Bso.head(5)
This Api compiles the data released by the state health departments. However, there is a difference between the records of the state and city health departments, and the state records are out of date in relation to those of the cities. I would like to update Thursdays and Saturdays (the day when the epidemiological week ends). I'm trying the following:
saturday = datetime.today() + timedelta(days=-5)
yesterday = datetime.today() + timedelta(days=-1)
last_available_confirmed_day_Bso_saturday = 51
last_available_confirmed_day_Bso_yesterday = 54
df_Bso = df_Bso.loc[df_Bso['date'] == saturday, ['last_available_confirmed']] = last_available_confirmed_day_Bso_saturday
df_Bso = df_Bso.loc[df_Bso['date'] == yesterday, ['last_available_confirmed']] = last_available_confirmed_day_Bso_yesterday
df_Bso
However, I get the error:
> AttributeError: 'int' object has no attribute 'loc'
I need another dataframe with the values of these days updates. Can anyone help?
You have to adjust the date. Your data frame date column is a string. You can convert them to datetime.
today = datetime.now()
last_sat_num = (today.weekday() + 2) % 7
last_thu_num = (today.weekday() + 4) % 7
last_sat = today - timedelta(last_sat_num)
last_thu = today - timedelta(last_thu_num)
last_sat_str = last_sat.strftime('%Y-%m-%d')
last_thu_str = last_thu.strftime('%Y-%m-%d')
last_available_confirmed_day_Bso_sat = 51
last_available_confirmed_day_Bso_thu = 54
df_Bso2 = df_Bso.copy()
df_Bso2.loc[df_Bso2['date'] == last_sat_str, ['last_available_confirmed']] = last_available_confirmed_day_Bso_sat
df_Bso2.loc[df_Bso2['date'] == last_thu_str, ['last_available_confirmed']] = last_available_confirmed_day_Bso_thu
df_Bso2[['date', 'last_available_confirmed']].head(10)
Output
date last_available_confirmed
0 2020-07-15 44
1 2020-07-14 43
2 2020-07-13 40
3 2020-07-12 40
4 2020-07-11 51
5 2020-07-10 39
6 2020-07-09 36
7 2020-07-08 36
8 2020-07-07 27
9 2020-07-06 27
I am writing a script that scrapes all gpu's from a site, puts them in a csv. Then it should compare the csv from today with the one from yesterday, and see if there are gpus with the same name but a different price (so i can see price drops). I am currently stuck on this. Can anyone help?
Code:
from selenium import webdriver
from bs4 import BeautifulSoup
import time
import datetime
import pandas as pd
import numpy as np
class Scraper():
def __init__(self):
url = 'https://www.megekko.nl/Computer/Componenten/Videokaarten'
PATH = 'E:/win21/chromedriver_win32/chromedriver.exe'
self.driver = webdriver.Chrome(PATH)
self.today = str(datetime.date.today()).replace('-', '').replace(' ', '').replace(':','').replace('.', '')
self.yesterday = str(int(self.today) - 1)
self.fname = self.today + "products.csv"
self.f = open(self.fname, 'a')
self.fname2 = self.yesterday + "products.csv"
self.f = open(self.fname2, "a")
self.names = []
self.deliverytimes = []
self.prices = []
self.differences = []
self.driver.get(url)
self.filter()
# self.main(28)
self.compare(self.today + "products.csv", self.yesterday + "products.csv")
self.driver.close()
def main(self, ScrapedPages):
#Loop trough each page and get its data
for i in range(ScrapedPages):
self.soup = BeautifulSoup(self.driver.page_source, 'html.parser')
self.get_data()
self.export_data()
#Function to go to the next page
def next_page(self):
time.sleep(1)
next_page_element = self.driver.find_element_by_xpath('html/body/div[1]/main/div[1]/div[5]/div[1]/div[3]/img')
self.driver.execute_script("arguments[0].click();", next_page_element)
time.sleep(1)
def export_data(self):
raw_data = {"name": self.names,
"deliverytime": self.deliverytimes,
"price": self.prices}
self.df = pd.DataFrame(raw_data, columns = ['name', 'deliverytime', 'price'])
self.df.to_csv(self.today + "products.csv", index=False)
def append_data(self):
self.names.append(self.name)
self.deliverytimes.append(self.delivery_time)
self.prices.append(self.price)
print(self.name)
print(self.delivery_time)
print(self.price + "\n")
def get_data(self):
for self.container in self.soup.find_all('div', {'class':'navProductListitem'}):
self.name = self.container.div.img['title']
price_container = self.container.find_all('div', {'class':'euro'})
self.price = price_container[0]
self.price = self.price.text.strip()
self.price = self.price.replace(",", "").replace("-", "").replace('"', "")
self.price += ",-"
delivery_time_container = self.container.find_all('div', {'class':'voorraad'})
self.delivery_time = delivery_time_container[0].text.strip()
self.append_data()
self.next_page()
def compare(self, file1, file2):
df1 = pd.read_csv(file1)
df2 = pd.read_csv(file2)
df_merged = pd.concat([df1, df2])
duplicates_df = df_merged[df_merged.duplicated(['name'])]
duplicates_df.to_csv("TEST1.csv")
print(duplicates_df)
# df_merged.insert(3, "Difference", "")
df_merged.to_csv("TEST2.csv", index=False)
def filter(self):
amd_checkbox_elem = self.driver.find_element_by_xpath('html/body/div/main/div[1]/div[5]/div[3]/div/div[5]/div/div[2]/label')
self.driver.execute_script("arguments[0].click();",amd_checkbox_elem)
time.sleep(2)
nvidia_checkbox_elem = self.driver.find_element_by_xpath('html/body/div/main/div[1]/div[5]/div[3]/div/div[5]/div/div[1]/label')
self.driver.execute_script("arguments[0].click();",nvidia_checkbox_elem)
time.sleep(2)
if __name__ == '__main__':
app = Scraper()
print("finished")
You can see that i was messing around with the compare function, but it doesn't work yet.
Example of what it should do:
File Yesterday:
RTX 2080Ti, $1250
RX 580, $200
File Today:
RTX 2080Ti, $1200
RX 580, $200
The compare function should make a csv/dataframe containing the rtx 2080ti with its price from today. The rx 580 should be ignored
Example on how the csv files are structured:
I tried to reproduce your situation. Dataframe from yesterday:
df_yesterday = pd.DataFrame({"name":["RTX 2080Ti","RX 580","RA 200", "GPU X"],
"delivery_time": ["some value"]* 4,
"price":[1250,200,100,300]})
df_yesterday
name delivery_time price
0 RTX 2080Ti some value 1250
1 RX 580 some value 200
2 RA 200 some value 100
3 GPU X some value 300
Dataframe from today:
df_today = pd.DataFrame({"name":["RTX 2080Ti","RX 580","RA 200", "GPU X"],
"delivery_time": ["some value"]* 4,
"price":[1200,250,90,300]})
df_today
name delivery_time price
0 RTX 2080Ti some value 1200
1 RX 580 some value 250
2 RA 200 some value 90
3 GPU X some value 300
Note that for RTX 2080Ti and RA 200 the price is lower than yesterday, whereas for RX 580 is higher today than yesterday.
Then you can concatenate the two table, remove rows with same values (GPU with same price as yesterday), and finally keep only the value from today:
df_merged = pd.concat([df_yesterday, df_today]).reset_index(drop=True)
df_merged.drop_duplicates(keep=False, inplace=True) #remove GPU if the price is the same as yesterday
duplicates_df = df_merged.groupby(by="name").last()
duplicates_df
Output dataframe:
delivery_time price
name
RA 200 some value 90
RTX 2080Ti some value 1200
RX 580 some value 250
The application should search one of the column in an excel and and display corresponding column as a result but i am not able to get the values. I think i am not able to map the dictionary to the display tab using tkinter. Please help.
Below file is in outlook
Search (Input) Result (Output)
1 a
2 b
3 c
4 d
from tkinter import *
import tkinter.messagebox
import pandas as pd
root=Tk()
root.geometry('450x550')
root.title("Welcome")
root.configure(background="silver")
#Entry widget object
textin=StringVar()
**exlist = pd.read_excel('foo6.xls', index_col=0).to_dict('index')**
def clk():
entered = ent.get()
output.delete(0.0,END)
try:
textin = exlist[entered]
except:
textin = 'SORRY NO INFO \n AVAILABLE!!!!!!!!\n'
output.insert(0.0,textin)
def ex():
tkinter.messagebox.showinfo("Program",'Exit')
exit()
def exitt():
tkinter.messagebox.showinfo("Program",'Exit')
exit()
def me():
text='\n XYZ \n Piyushrkc \n Nice'
saveFile=open('text.txt','w')
saveFile.write(text)
print('This are the entries::',text)
def hel():
help(tkinter)
def cont():
tkinter.messagebox.showinfo("S/W Contributors",'\n Piyush ___Version 1.0___')
def clr():
textin.set(" ")
menu = Menu(root)
root.config(menu=menu)
subm = Menu(menu)
menu.add_cascade(label="File",menu=subm)
subm.add_command(label="Memo",command=me)
subm.add_command(label="Save")
subm.add_command(label="Save As")
subm.add_command(label="Print")
subm.add_command(label="Exit",command=ex)
subm1 = Menu(menu)
menu.add_cascade(label="Tools",menu=subm1)
subm1.add_command(label="Tkinter Help",command=hel)
subm2 = Menu(menu)
menu.add_cascade(label="About",menu=subm2)
subm2.add_command(label="Contributors",command=cont)
lab=Label(root,text='Name :',font=('none 20 bold'))
lab.grid(row=0,column=1,sticky=W)
ent=Entry(root,width=20,font=('none 18 bold'),textvar=textin,bg='white')
ent.grid(row=0,column=2,sticky=W)
but=Button(root,padx=2,pady=2,text='Submit',command=clk,bg='powder blue',font=('none 18 bold'))
but.place(x=100,y=90)
but4=Button(root,padx=2,pady=2,text='Clear',font=('none 18 bold'),bg='powder blue',command=clr)
but4.place(x=220,y=90)
output=Text(root,width=20,height=8,font=('Time 20 bold'),fg="black")
output.place(x=100,y=200)
labb=Label(root,text='Results',font=('non 18 bold'))
labb.place(x=0,y=180)
but1=Button(root,padx=2,pady=2,text='Exit',command=exitt,bg='powder blue',font=('none 18 bold'))
but1.place(x=200,y=470)
root.mainloop()
First of all I wanna emphasize that I'm a total beginner at python, the below code I made to manipulate some data from a CSV. I know that it's not the prettiest code and probably I could have made it more elegant, but it works, until a certain point and that's the reason I opened this question
import csv
from numpy import interp
from operator import sub
import math
import pandas as pd
from Tkinter import *
import Tkinter as tk
import tkFileDialog as filedialog
root = Tk()
root.withdraw()
filename= filedialog.askopenfilename( initialdir="C:/", title="select file", filetypes=(("CSV files", "*.CSV"), ("all files", "*.*")))
id_uri = []
ore = []
minute = []
zile = []
activi = []
listx = []
listsa = []
list_ore = []
listspi = []
listspf = []
list_min = []
zile_luna = 0
test = []
nume = []
with open (filename) as p, open ('activi.csv') as a:
reader = csv.reader(p,delimiter=',')
for row in reader:
id_uri.append(row[0])
ore.append(row[1])
minute.append(row[2])
zile.append(row[3])
reader = csv.reader(a)
for row in reader:
activi.append(row[0])
nume.append(row[1])
id_uri = map(int, id_uri)
ore = map(float, ore)
minute = map(float, minute)
minute = interp(minute,[0,60],[0,100])
ore = ore + minute/100
zile = map(int, zile)
activi = map(int, activi)
zile_luna = len(set(zile))+1
mimin = 0
maxim = 0
def pontaj():
global listx
global listsa
global listspi
global listspf
global list_ore
global list_min
global maxim
global minim
for x in range(3):
for y in range(len(id_uri)):
if zile[y] == z:
if activi[x] == id_uri[y]:
listx.append(ore[y])
minim = min(listx)
maxim = max(listx)
listsa.append(maxim-minim)
listx = []
listspi = [int(i) for i in listsa]
listspf = [i%1 for i in listsa]
for i in range(len(listspf)):
listspf[i] = round(listspf[i], 2)
listspf[i] = listspf[i]*100
listspf[i] = interp(listspf[i],[0,100],[0,60])
listspf[i] = int(listspf[i])
list_ore.append(listspi)
list_min.append(listspf)
listsa = []
for z in range(1,zile_luna):
pontaj()
for sublst in list_ore:
for item in range(len(sublst)):
sublst[item] = str(sublst[item])
for sublst in list_min:
for item in range(len(sublst)):
sublst[item] = str(sublst[item])
for i in range(len(list_ore)):
for j in range(len(list_ore[i])):
list_ore[i][j] = ' '.join(i + ':' + j for i,j in zip(list_ore[i][j],list_min[i][j]))
df = pd.DataFrame(list_ore)
df = df.T
nume = pd.Series(nume)
df['e'] = nume.values
df.to_csv('pontaj.csv', index = False, header = False)
print df
and the CSV file I read all the info from looks like this(employee code, hour, minute, day):
23,5,00,1
23,6,00,1
24,7,00,1
25,8,00,1
24,9,00,1
25,11,00,1
24,7,00,2
25,8,00,2
24,9,00,2
25,11,00,2
23,5,00,4
23,6,00,4
24,7,00,4
25,8,00,4
24,9,00,4
25,11,00,4
I have another CSV file that has employee code folowed by employee name like this:
23,aqwe
24,beww
25,cwww
Basically it's an attendance logger, it compares info from one CSV to another, finds the min and max hours in a certain day, subtracts min from max and writes this info in a list that is written to another csv.
Thing is, if all employees attend a certain day, all goes well, it calculates the attendance hours, puts them in the csv, all good. But what will happen if an employee skips one day? well as I found out, it ruins the calculation, because the code requires that all data must be consistent and in a perfect order.
The data written to the CSV file must finally look like this:
day1 day2 day3
hours hours hours employee_a
hours hours hours employee_b
hours hours hours employee_c
But if one skips a day, the hours get scrambled.
I've tried some different approaches but none worked, and I realize the problem is due to my simple way of thinking, but as I said, I only started with python a few days ago.
Do you have any suggestions on how I could improve the code to take the missed day of a certain employee in consideration and generate the data like so:
day1 day2 day3
1:20 2:30 3:40 employee_a
1:20 2:30 3:40 employee_b
0:0 2:30 3:40 employee_c
Any advice would be appreciated, thanks!
I have a cust_peformat_test.csv file with this content:
AV-IM-1-13991730,6,2014-06-01 00:10,0.96
AV-IM-1-13991730,6,2014-06-01 00:15,0.92
AV-IM-1-13991730,6,2014-06-01 00:20,0.97
AV-IM-1-13991731,6,2014-06-01 00:10,1.96
AV-IM-1-13991731,6,2014-06-01 00:15,1.92
AV-IM-1-13991731,6,2014-06-01 00:20,1.97
AV-IM-1-13991732,6,2014-06-01 00:10,2.96
AV-IM-1-13991732,6,2014-06-01 00:15,2.92
AV-IM-1-13991732,6,2014-06-01 00:20,2.97
I wrote a python script to reformat this file to generate two more files whose content looks like this:
File-1: custpower.csv:
# file...... Recorder file
# date...... Thu Mar 12 14:35:32 2015
# user...... Sri
# host...... (null)
# group..... None
# property.. Avista Measurements
# limit.....
# interval..
# timestamp
2014-06-01 00:15,0.92,1.92,2.92
2014-06-01 00:20,0.97,1.97,2.97
2014-06-01 00:10,0.96,1.96,2.96,
File-2:powersensornames.csv:
AV-IM-1-13991730,AV-IM-1-13991731,AV-IM-1-13991732,
and that is exactly what I want and it works perfect unless if the data of my cust_peformat_test.csv is not well organized and if it looks like this:
AV-IM-1-13991730,6,2014-06-01 00:10,0.96
AV-IM-1-13991730,6,2014-06-01 00:15,0.92
AV-IM-1-13991731,6,2014-06-01 00:15,1.92
AV-IM-1-13991731,6,2014-06-01 00:20,1.97
AV-IM-1-13991730,6,2014-06-01 00:20,0.97
AV-IM-1-13991731,6,2014-06-01 00:10,1.96
AV-IM-1-13991732,6,2014-06-01 00:10,2.96
AV-IM-1-13991732,6,2014-06-01 00:15,2.92
AV-IM-1-13991732,6,2014-06-01 00:20,2.97
that messes up the content of custpower.csv and looks like this:
# file...... Recorder file
# date...... Thu Mar 12 14:35:32 2015
# user...... Sri
# host...... (null)
# group..... None
# property.. Avista Measurements
# limit.....
# interval..
# timestamp
2014-06-01 00:15,1.96,2.96,,,2.92
2014-06-01 00:20,,,,,2.97
which is not correct. Its been a pain trying to figure out what is wrong with my code and this is my code:
'''
Created on Jun 18, 2015
#author: sg
'''
#import datetime
#import csv
'''
#cust_power_real_recorder = open("Custmeters_preformat.csv",'w')
cust_power_real_reader = csv.reader(open("SPU123_customer_meters_power_kw.csv",'r'),delimiter=',')
spu123_meters=[]
for i,line in enumerate(cust_power_real_reader):
if i>0:
#d = datetime.datetime.strptime(line[6],'%Y-%m-%d %H:%M:%S')
if line[5][8:] not in spu123_meters:
spu123_meters.append(line[5][8:])
#cust_power_real_recorder.writelines([line[5],',6,',line[6],',',line[10],'\n'])
#cust_power_real_recorder.close()
'''
'''open('data.csv','w').write(
"""\
13986513,6,6/1/2014 12:00:00 AM,248.7
13986513,6,6/1/2014 12:00:05 AM,248.4
13986513,6,6/1/2014 12:00:10 AM,249
13986513,6,6/1/2014 12:00:15 AM,249.3
13986513,6,6/1/2014 12:00:20 AM,249.3
13986513,6,6/1/2014 12:00:25 AM,249.3
13986513,6,6/30/2014 11:55:00 PM,249.3
13986534,6,6/1/2014 12:00:00 AM,249
13986534,6,6/1/2014 12:00:05 AM,249
13986534,6,6/1/2014 12:00:10 AM,249.3
13986534,6,6/1/2014 12:00:15 AM,249.6
13986534,6,6/30/2014 11:55:00 PM,249.7\
""")
'''
header = '''# file...... Recorder file
# date...... Thu Mar 12 14:35:32 2015
# user...... Sri
# host...... (null)
# group..... None
# property.. Avista Measurements
# limit.....
# interval..'''
#DECLARE THE FILE YOU WANT TO SPIT OUT
#testvolt = open("testvolt.csv",'w')
#testvolt.writelines([header,'\n','# timestamp\n'])
testpower = open("custpower.csv",'w')
testpower.writelines([header,'\n','# timestamp\n'])
class ReadSensorLines(object):
def __init__(self, filename):
sensor_offsets = {}
sensors = []
readfp = open(filename, "rb")
readfp.readline() # skip header
# find start of each sensor
# use readline not iteration so that tell offset is right
offset = readfp.tell()
sensor = ''
while True:
line = readfp.readline()
if not line:
break
next_sensor = line.split(',', 1)[0]
if next_sensor != sensor:
if sensor:
sensors.append(sensor)
next_offset = readfp.tell()
sensor_offsets[sensor] = [offset, next_offset - offset]
sensor = next_sensor
offset = next_offset
else:
# setup for first sensor
sensor = next_sensor
if next_sensor:
sensors.append(next_sensor)
sensor_offsets[next_sensor] = [offset, readfp.tell() - offset]
self.readfp = readfp
self.sensor_offsets = sensor_offsets
self.sensors = sensors
def read_sensor(self, sensorname):
pos_data = self.sensor_offsets[sensorname]
self.readfp.seek(pos_data[0])
line = self.readfp.readline(pos_data[1])
pos_data[0] += len(line)
pos_data[1] -= len(line)
return line
#property
def data_remains(self):
return any(pos_data[1] for pos_data in self.sensor_offsets.itervalues())
def close(self):
self.readfp.close()
sensor_lines = ReadSensorLines("cust_peformat_test.csv") #READ THE CVS FILE U WANT TO MODIFY.
#In abive, delete.csv is for voltage recorder generation and Custmeters_preformat.csv is for power recorder generation
AllSensors=[]
while sensor_lines.data_remains:
row = []
for sensor in sensor_lines.sensors:
if sensor not in AllSensors:
AllSensors.append(sensor)
sensor_line = sensor_lines.read_sensor(sensor)
if sensor_line:
_, _, date, volts = sensor_line.strip().split(',')
row.append(volts)
else:
row.append('')
row.insert(0, date)
#print ','.join(row)
#print row
'''
#below if else is ONLY for voltage csv files
if '2014-06-' not in row[0]:
row[0] = str(datetime.datetime.strptime(row[0],'%m/%d/%Y %H:%M'))
else:
row[0] = str(datetime.datetime.strptime(row[0],'%Y-%m-%d %H:%M:%S'))
#voltage csv file if else case ENDS
'''
#testvolt.writelines([','.join(row),'\n']) # this is for voltage files
testpower.writelines([','.join(row),'\n']) # this is for power files
sensornames = open("powersensornames.csv",'w') #THIS IS THE FILE WHERE THE HEADERS ARE WRITTEN
#In above, sensornames.csv is for voltage recorder and powersensornames.csv is for power recorder generation
for asensor in AllSensors:
sensornames.writelines([asensor,','])