Storing and processing data based on timezone

hi guys, I am very new to influxdb but it seems to be the answer to my problems and I am hoping someone could help me with a problem im trying to solve using influxdb.
I want to make calculations based on reading from sensors that are pushing data to my server and my data looks something like this that gets pushed in real time to the server one timestamp at a time
timestamp current_val1 current_val2 timezone deviceid
1525967203 20 21 ‘Europe/Dublin’ sssss
1525967223 22 24 ‘Europe/Dublin’ sssss

I want to store the data into influxdb by transforming them into
timestamp current_val1 current_val2 timezone ph1 ph2 deviceid
1525967203 20 21 ‘Europe/Dublin’ 0 0 sssss
1525967223 22 24 ‘Europe/Dublin’ 2 3 sssss

Basically, I want to

  1. check if there is already a timestamp from that current day (timezone aware)
  2. if it doesn’t exist, insert a 0 into the ph fields
  3. if it exists subtract the last current_val of the current day and from the current_val and insert it into the ph respectively

I am not sure if this should be done during processing or during the insertion and if i can do this directly inside the database with a query. I have looked around on SO and couldn’t find a satisfactory answer to the same and would really appreciate some info from your guys.

Thanks