Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Egna datormiljön
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDP003 - Projekt
Egna datormiljön
Commits
4896a698
Commit
4896a698
authored
6 months ago
by
Oliwer Mattsson
Browse files
Options
Downloads
Patches
Plain Diff
Laddade upp godkänd datalager.
parent
6145e18d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MyPortfolio/data.py
+93
-19
93 additions, 19 deletions
MyPortfolio/data.py
with
93 additions
and
19 deletions
MyPortfolio/data.py
+
93
−
19
View file @
4896a698
...
...
@@ -11,10 +11,12 @@ import os
import
json
import
pprint
import
re
import
unicodedata
from
operator
import
itemgetter
# ---- IMPORTS ---- #
def
load
(
filename
):
try
:
...
...
@@ -35,14 +37,18 @@ def save(data):
file
.
close
()
# Update unique techniques if user added new ones to the file.
get_techniques_stats
(
data
)
# Reload data
load
()
# Get project count
def
get_project_count
(
data
):
return
len
(
data
)
# Get project by ID
def
get_project
(
data
,
id
):
...
...
@@ -50,12 +56,6 @@ def get_project(data, id):
if
data
[
n
][
'
project_id
'
]
==
id
:
return
data
[
n
]
# Get project count
def
get_project_count
(
data
):
return
len
(
data
)
# Get all unique techniques from project
...
...
@@ -94,7 +94,11 @@ def get_technique_stats(data):
# Fetches and sorts projects matching criteria from the specified list.
def
search
(
data
,
sort_by
=
'
project_id
'
,
sort_order
=
'
desc
'
,
techniques
=
None
,
search
=
None
,
search_field
=
None
):
def
search
(
data
,
sort_by
=
'
start_date
'
,
sort_order
=
'
desc
'
,
techniques
=
None
,
search
=
None
,
search_fields
=
None
):
if
type
(
search
)
==
str
:
search
=
search
.
lower
()
results
=
[]
# get it
...
...
@@ -102,16 +106,88 @@ def search(data, sort_by='project_id', sort_order='desc', techniques=None, searc
results
.
append
(
project
)
# sort it
sorted_list
=
sorted
(
results
,
key
=
itemgetter
(
sort_by
))
results
=
sorted
(
results
,
key
=
itemgetter
(
sort_by
))
# order it
if
sort_order
==
'
a
sc
'
:
results
.
reverse
()
if
sort_order
==
'
de
sc
'
:
results
.
reverse
()
# filter it (by techniques)
for
project
in
sorted_list
:
pass
if
techniques
!=
None
:
for
technique
in
get_techniques
(
data
):
for
project
in
results
:
if
all
(
n
in
project
[
'
techniques_used
'
]
for
n
in
techniques
):
pass
else
:
results
.
pop
(
results
.
index
(
project
))
# search for it
if
search
!=
None
:
pass
search_results
=
[]
for
project
in
results
:
if
search_fields
!=
None
and
search_fields
!=
""
and
search
!=
""
:
for
field
in
search_fields
:
substring
=
project
[
field
]
if
type
(
substring
)
==
str
:
substring
=
substring
.
lower
()
if
substring
.
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
if
type
(
substring
)
==
int
:
if
str
(
substring
).
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
if
type
(
substring
)
==
list
:
for
subsubstring
in
substring
:
if
type
(
subsubstring
)
==
str
:
if
subsubstring
.
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
if
type
(
subsubstring
)
==
int
:
if
str
(
subsubstring
).
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
elif
search_fields
==
""
:
results
.
clear
()
break
else
:
for
substring
in
list
(
project
.
values
()):
substring
=
substring
.
lower
()
print
(
type
(
substring
))
if
type
(
substring
)
==
str
:
if
substring
.
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
if
type
(
substring
)
==
int
:
if
str
(
substring
).
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
if
type
(
substring
)
==
list
:
for
subsubstring
in
substring
:
if
type
(
subsubstring
)
==
str
:
if
subsubstring
.
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
if
type
(
subsubstring
)
==
int
:
if
str
(
subsubstring
).
find
(
search
)
!=
-
1
:
search_results
.
append
(
project
)
break
results
=
search_results
#pprint.pp(results)
return
results
...
...
@@ -196,7 +272,6 @@ def edit_project(data, id):
def
delete_project
(
data
):
pass
...
...
@@ -245,15 +320,14 @@ def menu(data):
def
main
():
data
=
load
(
'
data.json
'
)
menu
(
data
)
data
=
load
(
'
MyPortfolio/
data.json
'
)
#
menu(data)
get_technique_stats
(
data
)
#search(data, 'project_id', 'desc')
if
__name__
==
"
__main__
"
:
main
()
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