Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80845934
gen_ch.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 2, 21:45
Size
3 KB
Mime Type
text/x-python
Expires
Wed, Sep 4, 21:45 (2 d)
Engine
blob
Format
Raw Data
Handle
20452815
Attached To
R11149 PDM-Nicola-Oulu
gen_ch.py
View Options
import
random
from
gen_master
import
*
class
GenDataCH
(
GenData
):
def
__init__
(
self
,
home_path
):
super
()
.
__init__
(
home_path
)
self
.
abrev
=
"ch"
self
.
keys
=
[
"surname"
,
"givenName"
,
"dateOfBirth"
,
"height"
,
"placeOfOrigin"
,
"dateOfIssue"
,
"dateOfExpiry"
,
"sex"
,
"identityCard"
,
"nationality"
]
self
.
keys_all
=
[
"surname"
,
"givenName"
,
"dateOfBirth"
,
"height"
,
"placeOfOrigin"
,
"dateOfIssue"
,
"dateOfExpiry"
,
"sex"
,
"identityCard"
,
"nationality"
,
"code"
]
self
.
schema
=
{
"surname"
:
"NAME - NOM - COGNOME - NUM - SURNAME"
,
"givenName"
:
"VORNAME(N) - PRENOMS(S) - NOME(I) - PRENUM(S) - GIVEN NAME(S)"
,
"dateOfBirth"
:
"GEBURTSDATUM - DATE DE NAISSANCE - DATA DI NASCITA - DATA DA NASCHIENTSCHA - DATE OF BIRTH"
,
"height"
:
"GRÖSSE - TAILLE - STATURA - GRONDEZZA - HEIGHT"
,
"placeOfOrigin"
:
"HEIMATORT - LIEU D'ORIGINE - LUOGO DI ATTINENZA - LIEU D'ORIGIN - PLACE OF ORIGIN"
,
"authority"
:
"BEHÖRDE - AUTORITÉ - AUTORITÀ - AUTORIDAD - AUTHORITY"
,
"dateOfIssue"
:
"AUSGESTELLT AM - DÉLIVERÉE LE - RILASCIATA IL - EMESSA ILS - DATE OF ISSUE"
,
"dateOfExpiry"
:
"GÜLTIG BIS - DATE D'EXPIRATION - DATA DI SCADENZA - DATA DA SCADENZA - DATE OF EXPIRY"
,
"nationality"
:
"NATIONALITÄT - NATIONALITÉ - CITTADINAZA - NAZIUNALITAD - NATIONALITY"
,
"identityCard"
:
"IDENTITÄTSKARTE - CARTE D'IDENTITÉ - CARTA DiDENTITÀ - CARTA D'IDENTITAD - IDENTITY CARD"
,
"sex"
:
"GESCHLECHT - SEE - SESSO - SCHLATTAINA - SEX"
,
"code"
:
"CODE"
}
# protected functions
def
_get_firstName
(
self
):
with
open
(
'data.json'
,
'r'
)
as
fp
:
data
=
json
.
load
(
fp
)
random
.
seed
(
42
)
# only keep first name, sometimes there are "Bob and Anna"
first_names
=
[
x
.
split
(
', '
,
2
)[
1
]
for
x
in
data
[
"name"
]
if
(
", "
in
x
)]
first_names
=
[
x
for
x
in
first_names
if
x
is
not
None
]
first_names
=
[
x
.
split
(
' '
)[
0
]
for
x
in
first_names
]
return
first_names
def
_get_lastName
(
self
):
with
open
(
'data.json'
,
'r'
)
as
fp
:
data
=
json
.
load
(
fp
)
random
.
seed
(
42
)
last_names
=
[
x
.
split
(
', '
,
2
)[
0
]
for
x
in
data
[
"name"
]
if
(
", "
in
x
)]
last_names
=
[
x
for
x
in
last_names
if
x
is
not
None
]
return
last_names
def
_get_city
(
self
):
with
open
(
'data.json'
,
'r'
)
as
fp
:
data
=
json
.
load
(
fp
)
random
.
seed
(
42
)
place_of_origion
=
[
x
for
x
in
data
[
"location"
]
if
(
x
is
not
None
)]
return
place_of_origion
def
_gen_date_
(
self
,
d
,
m
,
y
):
return
self
.
_strnum
(
d
)
+
" "
+
self
.
_strnum
(
m
)
+
" "
+
str
(
y
)[
2
:
4
]
def
_gen_identityCard
(
self
):
abc
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
nb
=
abc
[
random
.
randint
(
0
,
len
(
abc
)
-
1
)]
nb
+=
self
.
_strnum
(
random
.
randint
(
100
,
9999999
),
min_len
=
7
)
return
nb
def
_get_answer
(
self
,
key
):
# is not yet selfconsistent : age-height; dateofIssue-dateof Expiery
if
key
==
"surname"
:
return
self
.
fake_data
[
"last name"
]
elif
key
==
"givenName"
:
return
self
.
fake_data
[
"first name"
]
elif
key
==
"dateOfBirth"
:
return
self
.
_gen_date
(
1940
,
2020
)
elif
key
==
"height"
:
return
[
random
.
randint
(
100
,
180
)]
elif
key
==
"placeOfOrigin"
:
return
self
.
fake_data
[
"city"
]
elif
key
==
"dateOfIssue"
:
return
self
.
_gen_date
(
2010
,
2020
)
elif
key
==
"dateOfExpiry"
:
return
self
.
_gen_date
(
2020
,
2030
)
elif
key
==
"sex"
:
return
[
"M"
,
"F"
]
elif
key
==
"identityCard"
:
return
[
self
.
_gen_identityCard
()]
elif
key
==
"nationality"
:
return
[
"Schweiz - Suisse - Svizzera - Svizra - Switzerland"
]
else
:
raise
NotImplementedError
(
"key not known"
)
Event Timeline
Log In to Comment