Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91159070
gen_de_label.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
Fri, Nov 8, 12:08
Size
4 KB
Mime Type
text/x-python
Expires
Sun, Nov 10, 12:08 (2 d)
Engine
blob
Format
Raw Data
Handle
22208312
Attached To
R11149 PDM-Nicola-Oulu
gen_de_label.py
View Options
import
random
from
gen_master
import
*
class
GenDataDEL
(
GenData
):
def
__init__
(
self
,
home_path
):
super
()
.
__init__
(
home_path
)
self
.
abrev
=
"de"
self
.
keys
=
[
"surname"
,
"givenName"
,
"dateOfBirth"
,
"height"
,
"dateOfIssue"
,
"dateOfExpiry"
,
"identityCard"
,
"eyeColor"
,
"placeOfBirth"
,
"nationality"
]
self
.
keys_all
=
[
"surname"
,
"givenName"
,
"dateOfBirth"
,
"height"
,
"authority"
,
"dateOfIssue"
,
"dateOfExpiry"
,
"identityCard"
,
"signature"
,
"eyeColor"
,
"placeOfBirth"
,
"ArtistName"
,
"address"
,
"nationality"
]
self
.
schema
=
{
"surname"
:
"Name - Surname - Nom"
,
"givenName"
:
"Vornamen - Given names - Prénoms"
,
"dateOfBirth"
:
"Geburtstag - Date of birth - Date de naissance"
,
"height"
:
"I am a label"
,
"authority"
:
"Behörde - Authority - Autorité"
,
"dateOfIssue"
:
"Datum - Date - Date"
,
"dateOfExpiry"
:
"Gültig bis - Date of expiry - Date d'expiration"
,
"identityCard"
:
"PERSONALAUSWEIS - IDENTITY CARD - CARTE D'IDENTITE"
,
"signature"
:
"Unterschrit der Inhaberin/des Inhabers - Signature of bearer - Signature de la titulaire/du titulaire"
,
"eyeColor"
:
"Aufgenfarbe - Colour of eyes - Couleur des yeux"
,
"placeOfBirth"
:
"Geburtsort - Place of birth - Lieu de naissance"
,
"ArtistName"
:
"Ordens- oder Künstlername/Religious name or pseudonym/ Nom de religion ou pseudonyme"
,
"address"
:
"Anschrift - Adress - Adresse"
,
"nationality"
:
"Staatsangehörigkeit - Nationality - Nationalité"
,
}
# protected functions
def
_get_firstName
(
self
):
with
open
(
'data_germany.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_germany.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_geneva_city.json'
,
'r'
)
as
fp
:
data
=
json
.
load
(
fp
)
return
data
[
'region_de'
]
def
_gen_date_
(
self
,
d
,
m
,
y
):
return
self
.
_strnum
(
d
)
+
"."
+
self
.
_strnum
(
m
)
+
"."
+
self
.
_strnum
(
y
)
def
_gen_identityCard
(
self
):
abc
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789012345678901234567890123456789"
nb
=
""
while
len
(
nb
)
<
9
:
nb
+=
abc
[
random
.
randint
(
0
,
len
(
abc
)
-
1
)]
return
nb
def
_get_answer
(
self
,
key
,
set
=
None
):
# is not yet selfconsistent : age-height; dateofIssue-dateof Expiery
if
key
==
"surname"
:
if
set
is
None
:
return
self
.
fake_data
[
"last name"
]
return
self
.
data_sets
[
set
][
"last name"
]
elif
key
==
"givenName"
:
if
set
is
None
:
return
self
.
fake_data
[
"first name"
]
return
self
.
data_sets
[
set
][
"first name"
]
elif
key
==
"dateOfBirth"
:
return
self
.
_gen_date
(
1940
,
2020
)
elif
key
==
"height"
:
return
[
random
.
randint
(
100
,
180
)]
elif
key
==
"placeOfBirth"
:
if
set
is
None
:
return
self
.
fake_data
[
"city"
]
return
self
.
data_sets
[
set
][
"city"
]
elif
key
==
"dateOfIssue"
:
return
self
.
_gen_date
(
2010
,
2020
)
elif
key
==
"dateOfExpiry"
:
return
self
.
_gen_date
(
2020
,
2030
)
elif
key
==
"identityCard"
:
return
[
self
.
_gen_identityCard
()]
elif
key
==
"nationality"
:
return
[
"DEUTSCH"
]
elif
key
==
"eyeColor"
:
return
[
"bernstein"
,
"grün"
,
"grünbraun"
,
"grau"
,
"blau"
,
"hellbraun"
,
"hellblau"
,
"blaugrün"
]
else
:
raise
NotImplementedError
(
"key not known"
)
Event Timeline
Log In to Comment