Python: Read text file with time in hour, minutes and seconds; and angle in degree, arc minutes and arc seconds
Tag : python , By : Jakub Filak
Date : March 29 2020, 07:55 AM
To fix the issue you can do Using matplotlib.dates.datestr2num you could easily convert your first column to plottable numbers, but I did not find a function for your second column. You can build a function to process that, though: import numpy as np
def calc_hour( str ):
hour, min, sec = [float(i) for i in str.split(':')]
min += sec/60.
hour += min/60.
return hour
calc_hour = np.vectorize( calc_hour )
def calc_deg( str ):
deg, min, sec = [float(i) for i in str.split(':')]
min += sec/60.
deg += min/60.
return deg
calc_deg = np.vectorize( calc_deg )
values = np.loadtxt('tmp.txt', dtype=str)
hours= calc_hour( values[:,0] )
degs = calc_deg( values[:,1] )
hours = array([ 0.10133333, 0.11713889, 0.23825 , 0.38333333, 0.39730556,
0.39844444, 0.39983333, 0.40102778, 0.40105556, 0.40108333,
0.50836111])
degs = array([-70., -66., -59., -52., -49., -29., -28., -26., -14., 25., 30.])
import matplotlib.pyplot as plt
plt.plot(hours,degs)
|
Converting time, after 60 seconds it is only displaying the minutes. I am trying to display minutes followed by seconds.
Date : March 29 2020, 07:55 AM
it helps some times How do I display the seconds followed by the minutes like 1:20. Before the 60 seconds it displays the seconds but after the 60 seconds, it displays 1 mins. Following a tutorial but it is not what I am looking for. If you need more information let me know. , You could do like this private String parseDuration(int durationInSeconds) {
return String.format("%02dm :: ", durationInSeconds/60) + String.format("%02ds", durationInSeconds%60);
}
|
Parsing t=1h2m3s(h - hour, m-minutes, s-seconds ) into seconds if order of hours, minutes and seconds are valid
Date : March 29 2020, 07:55 AM
may help you . I would first check that the order matches then, if it does calculate the time in seconds. function calculateInSeconds(timeStamp) {
var timeInSeconds=0;
console.log("calculateInSeconds timeStamp:"+timeStamp);
if(timeStamp.match(/t=[0-9]*h?[0-9]*m?[0-9]*s?/g).toString()==timeStamp){
timeStamp.replace(/([0-9]+)[h|m|s]/g, function(match, value) {
if (match.indexOf("h") > -1) {
timeInSeconds += value * 60 * 60;
} else if (match.indexOf("m") > -1) {
timeInSeconds += value * 60;
} else if (match.indexOf("s") > -1) {
timeInSeconds += value * 1;
}
});
}
console.log("timeInSeconds"+timeInSeconds);
}
calculateInSeconds("t=1h2m");//3720 valid
calculateInSeconds("t=2m1h");//0 invalid
|
Change label text from Hours:Minutes:Seconds to Minutes:Seconds
Tag : chash , By : Terrence Poon
Date : March 29 2020, 07:55 AM
To fix the issue you can do if your time is string:then you can use : lbltime.Text = time.Remove(0, 3); lbltime.Text = mytime.ToString("mm:ss");
|
How to convert total seconds value to string in 'hours minutes seconds' format
Tag : chash , By : user106284
Date : March 29 2020, 07:55 AM
|