Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tkeqcut
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
Legacy
tkeqcut
Commits
5d205c0e
Commit
5d205c0e
authored
6 years ago
by
Lan Dam
Browse files
Options
Downloads
Patches
Plain Diff
convert to be compatible with py2 and py3
parent
89d13cc4
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
convert to be compatible with py2 and py3
Pipeline
#395
passed with stage
in 2 minutes and 50 seconds
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tkeqcut/LibTrace.py
+1506
-1414
1506 additions, 1414 deletions
tkeqcut/LibTrace.py
tkeqcut/TimeConvert.py
+137
-124
137 additions, 124 deletions
tkeqcut/TimeConvert.py
tkeqcut/tkeqcut.py
+1366
-1249
1366 additions, 1249 deletions
tkeqcut/tkeqcut.py
with
3009 additions
and
2787 deletions
tkeqcut/LibTrace.py
+
1506
−
1414
View file @
5d205c0e
This diff is collapsed.
Click to expand it.
tkeqcut/TimeConvert.py
+
137
−
124
View file @
5d205c0e
...
...
@@ -9,121 +9,134 @@
#
# cleaned up code
#
################################################################
#
# modification
# version: 2019.028
# author: Lan Dam
#
# convert to be compatible with both py2 and py3
from
sys
import
exit
from
string
import
join
import
time
,
sys
#time.timezone=0
from
os
import
environ
VERSION
=
"
20
07
.02
4
"
VERSION
=
"
20
19
.02
5
"
environ
[
'
TZ
'
]
=
'
GMT
'
time
.
tzname
=
(
'
GMT
'
,
'
GMT
'
)
time
.
timezone
=
0
time
.
timezone
=
0
###############################################
def
AddLeadZero
(
hms
)
:
"""
fcn to put zero in front of 0-9, returns time as string
"""
if
hms
<
10
:
return
'
0
'
+
str
(
hms
)
else
:
return
str
(
hms
)
"""
fcn to put zero in front of 0-9, returns time as string
"""
if
hms
<
10
:
return
'
0
'
+
str
(
hms
)
else
:
return
str
(
hms
)
###############################################
def
AddLeadZeroJday
(
jday
)
:
"""
sub to put zeros in front of jday, returns jday as string
"""
if
jday
<
10
:
return
'
00
'
+
str
(
jday
)
elif
jday
<
100
:
return
'
0
'
+
str
(
jday
)
else
:
return
str
(
jday
)
"""
sub to put zeros in front of jday, returns jday as string
"""
if
jday
<
10
:
return
'
00
'
+
str
(
jday
)
elif
jday
<
100
:
return
'
0
'
+
str
(
jday
)
else
:
return
str
(
jday
)
###############################################
def
Year4To2
(
y4
)
:
"""
convert from 4 digit to 2 digit year with floor of 1970, returns y4 as string
"""
y4
=
int
(
y4
)
if
y4
>=
1970
:
y4
-=
1900
else
:
exit
(
"
ERROR: Code does
'
t handle dates prior to 1970
"
)
if
y4
>=
100
:
y4
-=
100
y4
=
AddLeadZero
(
y4
)
return
str
(
y4
)
"""
convert from 4 digit to 2 digit year with floor of 1970, returns y4 as string
"""
y4
=
int
(
y4
)
if
y4
>=
1970
:
y4
-=
1900
else
:
exit
(
"
ERROR: Code does
'
t handle dates prior to 1970
"
)
if
y4
>=
100
:
y4
-=
100
y4
=
AddLeadZero
(
y4
)
return
str
(
y4
)
###############################################
def
Year2To4
(
y2
)
:
"""
convert from 2 digit year (since 1970) to 4 digit year, returns y2 as string
"""
y2
=
int
(
y2
)
if
y2
>=
70
and
y2
<
100
:
y2
+=
1900
elif
y2
>=
0
and
y2
<
70
:
y2
+=
2000
return
str
(
y2
)
"""
convert from 2 digit year (since 1970) to 4 digit year, returns y2 as string
"""
y2
=
int
(
y2
)
if
y2
>=
70
and
y2
<
100
:
y2
+=
1900
elif
y2
>=
0
and
y2
<
70
:
y2
+=
2000
return
str
(
y2
)
###############################################
def
CalDay
(
jday
,
year
)
:
"""
sub to convert from julian day to calendar day
days in calendar year [0]=normal [1]=leap
"""
days_in_month
=
(
[
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
],
[
0
,
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
]
)
"""
sub to convert from julian day to calendar day
days in calendar year [0]=normal [1]=leap
"""
days_in_month
=
(
[
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
],
[
0
,
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
]
)
# determine if leap year
if
year
%
4
==
0
and
year
%
100
!=
0
or
year
%
400
==
0
:
leap
=
1
else
:
leap
=
0
if
jday
==
366
and
leap
==
0
:
return
(
"
ERROR: Year
"
,
year
,
"
Does Not Have 366 Days
"
)
else
:
i
=
1
mon
=
0
mday
=-
1
while
jday
>
days_in_month
[
leap
][
i
]
:
jday
-=
days_in_month
[
leap
][
i
]
mon
=
i
mday
=
jday
i
+=
1
mon
+=
1
;
if
mday
<
0
:
mday
=
jday
return
mday
,
mon
if
year
%
4
==
0
and
year
%
100
!=
0
or
year
%
400
==
0
:
leap
=
1
else
:
leap
=
0
if
jday
==
366
and
leap
==
0
:
return
(
"
ERROR: Year
"
,
year
,
"
Does Not Have 366 Days
"
)
else
:
i
=
1
mon
=
0
mday
=-
1
while
jday
>
days_in_month
[
leap
][
i
]
:
jday
-=
days_in_month
[
leap
][
i
]
mon
=
i
mday
=
jday
i
+=
1
mon
+=
1
;
if
mday
<
0
:
mday
=
jday
return
mday
,
mon
###########################################
def
Epoch2EvtTime
(
epoch
)
:
"""
sub to determine epoch and search times
return to jday times for max time Note 1900=00
"""
(
year
,
month
,
day
,
hour
,
minute
,
second
,
weekday
,
yday
,
dst
)
=
time
.
gmtime
(
epoch
)
# if not dst : hour-=1
"""
sub to determine epoch and search times
return to jday times for max time Note 1900=00
"""
(
year
,
month
,
day
,
hour
,
minute
,
second
,
weekday
,
yday
,
dst
)
=
\
time
.
gmtime
(
epoch
)
# if not dst : hour-=1
# fix with zeros
second
=
AddLeadZero
(
second
)
minute
=
AddLeadZero
(
minute
)
hour
=
AddLeadZero
(
hour
)
yday
=
AddLeadZeroJday
(
yday
)
second
=
AddLeadZero
(
second
)
minute
=
AddLeadZero
(
minute
)
hour
=
AddLeadZero
(
hour
)
yday
=
AddLeadZeroJday
(
yday
)
# calc yyyydddhhmmss for get_trace
no_dot_time
=
join
(
map
(
str
,
(
year
,
yday
,
hour
,
minute
,
second
))
,
""
)
no_dot_time
=
""
.
join
(
map
(
str
,
(
year
,
yday
,
hour
,
minute
,
second
)))
# return year back to 2 digits
year
=
Year4To2
(
int
(
year
))
year
=
AddLeadZero
(
year
)
year
=
Year4To2
(
int
(
year
))
year
=
AddLeadZero
(
year
)
#
dot_time
=
join
(
map
(
str
,
(
year
,
yday
,
hour
,
minute
,
second
))
,
"
.
"
)
return
no_dot_time
,
dot_time
dot_time
=
"
.
"
.
join
(
map
(
str
,
(
year
,
yday
,
hour
,
minute
,
second
)))
return
no_dot_time
,
dot_time
################################
...
...
@@ -132,47 +145,47 @@ def Epoch2EvtTime(epoch) :
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
>
1
:
if
sys
.
argv
[
1
]
==
"
-#
"
:
print
VERSION
sys
.
exit
(
1
)
else
:
print
"
Unknown arguement %s
"
%
sys
.
argv
[
1
:]
sys
.
exit
(
1
)
print
"
\n
***Testing Functions***
"
print
"
\n
Testing AddLeadZero
"
for
x
in
range
(
5
,
20
,
10
)
:
print
"
\t
Input
"
,
x
,
"
: Output
"
,
AddLeadZero
(
x
)
print
"
\n
Testing AddLeadZeroJday
"
for
x
in
range
(
5
,
150
,
50
)
:
print
"
\t
Input
"
,
x
,
"
: Output
"
,
AddLeadZeroJday
(
x
)
print
"
\n
Testing Year4To2
"
for
x
in
range
(
1970
,
2050
,
35
)
:
print
"
\t
Input
"
,
x
,
"
: Output
"
,
Year4To2
(
x
)
print
"
\n
Testing Year2To4
"
for
x
in
range
(
0
,
100
,
35
)
:
print
"
\t
Input
"
,
x
,
"
: Output
"
,
Year2To4
(
x
)
print
"
\t
Input 04 : Output
"
,
Year2To4
(
04
)
print
"
\t
Input 96 : Output
"
,
Year2To4
(
96
)
print
"
\n
Testing CalDay
"
for
x
in
(
1
,
45
,
100
,
365
,
366
)
:
for
y
in
(
1970
,
2000
,
2010
,
2016
)
:
print
"
\t
Input
"
,
x
,
"
,
"
,
y
,
"
: Output
"
,
CalDay
(
x
,
y
)
print
"
\n
Testing Epoch2EvtTime
"
test_time
=
time
.
time
()
print
"
\t
TimeZone:
"
,
time
.
timezone
print
"
\t
Date:
"
,
time
.
ctime
(
test_time
)
print
"
\t
UTC:
"
,
time
.
gmtime
(
test_time
)
print
"
\t
Input
"
,
test_time
,
"
: Output
"
,
Epoch2EvtTime
(
test_time
)
test_string
=
(
1996
,
6
,
11
,
3
,
28
,
0
,
0
,
0
,
-
1
)
print
test_string
test_epoch
=
time
.
mktime
(
test_string
)
print
test_epoch
print
time
.
gmtime
(
test_epoch
)
print
Epoch2EvtTime
(
test_epoch
)
if
len
(
sys
.
argv
)
>
1
:
if
sys
.
argv
[
1
]
==
"
-#
"
:
print
(
VERSION
)
sys
.
exit
(
1
)
else
:
print
(
"
Unknown arguement %s
"
%
sys
.
argv
[
1
:]
)
sys
.
exit
(
1
)
print
(
"
\n
***Testing Functions***
"
)
print
(
"
\n
Testing AddLeadZero
"
)
for
x
in
range
(
5
,
20
,
10
)
:
print
(
"
\t
Input
"
,
x
,
"
: Output
"
,
AddLeadZero
(
x
)
)
print
(
"
\n
Testing AddLeadZeroJday
"
)
for
x
in
range
(
5
,
150
,
50
)
:
print
(
"
\t
Input
"
,
x
,
"
: Output
"
,
AddLeadZeroJday
(
x
)
)
print
(
"
\n
Testing Year4To2
"
)
for
x
in
range
(
1970
,
2050
,
35
)
:
print
(
"
\t
Input
"
,
x
,
"
: Output
"
,
Year4To2
(
x
)
)
print
(
"
\n
Testing Year2To4
"
)
for
x
in
range
(
0
,
100
,
35
)
:
print
(
"
\t
Input
"
,
x
,
"
: Output
"
,
Year2To4
(
x
)
)
print
(
"
\t
Input 04 : Output
"
,
Year2To4
(
0
o
4
)
)
print
(
"
\t
Input 96 : Output
"
,
Year2To4
(
96
)
)
print
(
"
\n
Testing CalDay
"
)
for
x
in
(
1
,
45
,
100
,
365
,
366
)
:
for
y
in
(
1970
,
2000
,
2010
,
2016
)
:
print
(
"
\t
Input
"
,
x
,
"
,
"
,
y
,
"
: Output
"
,
CalDay
(
x
,
y
)
)
print
(
"
\n
Testing Epoch2EvtTime
"
)
test_time
=
time
.
time
()
print
(
"
\t
TimeZone:
"
,
time
.
timezone
)
print
(
"
\t
Date:
"
,
time
.
ctime
(
test_time
)
)
print
(
"
\t
UTC:
"
,
time
.
gmtime
(
test_time
)
)
print
(
"
\t
Input
"
,
test_time
,
"
: Output
"
,
Epoch2EvtTime
(
test_time
)
)
test_string
=
(
1996
,
6
,
11
,
3
,
28
,
0
,
0
,
0
,
-
1
)
print
(
test_string
)
test_epoch
=
time
.
mktime
(
test_string
)
print
(
test_epoch
)
print
(
time
.
gmtime
(
test_epoch
)
)
print
(
Epoch2EvtTime
(
test_epoch
)
)
This diff is collapsed.
Click to expand it.
tkeqcut/tkeqcut.py
+
1366
−
1249
View file @
5d205c0e
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment