Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
geant-swd
compendium-v2
Commits
7444ac66
Commit
7444ac66
authored
1 year ago
by
Saket Agrahari
Browse files
Options
Downloads
Patches
Plain Diff
COMP-385 : Export data entry for all (sub)question regardless
parent
9d59bd03
No related branches found
No related tags found
1 merge request
!122
COMP-385 : Export data entry for all (sub)question regardless
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/routes/common.py
+36
-1
36 additions, 1 deletion
compendium_v2/routes/common.py
compendium_v2/routes/data_download.py
+9
-8
9 additions, 8 deletions
compendium_v2/routes/data_download.py
with
45 additions
and
9 deletions
compendium_v2/routes/common.py
+
36
−
1
View file @
7444ac66
...
@@ -3,9 +3,11 @@ Utilities used by multiple route blueprints.
...
@@ -3,9 +3,11 @@ Utilities used by multiple route blueprints.
"""
"""
import
functools
import
functools
import
logging
import
logging
from
itertools
import
product
from
compendium_v2
import
db
from
compendium_v2
import
db
from
compendium_v2.db.presentation_model_enums
import
CarryMechanism
,
ConnectionMethod
,
ConnectivityCoverage
from
compendium_v2.db.presentation_model_enums
import
CarryMechanism
,
ConnectionMethod
,
ConnectivityCoverage
,
\
UserCategory
from
compendium_v2.db.presentation_models
import
NREN
,
AlienWave
,
BudgetEntry
,
Capacity
,
CentralProcurement
,
\
from
compendium_v2.db.presentation_models
import
NREN
,
AlienWave
,
BudgetEntry
,
Capacity
,
CentralProcurement
,
\
CertificateProviders
,
ChargingStructure
,
CommercialChargingLevel
,
CommercialConnectivity
,
ConnectedProportion
,
\
CertificateProviders
,
ChargingStructure
,
CommercialChargingLevel
,
CommercialConnectivity
,
ConnectedProportion
,
\
ConnectionCarrier
,
ConnectivityGrowth
,
ConnectivityLevel
,
ConnectivityLoad
,
\
ConnectionCarrier
,
ConnectivityGrowth
,
ConnectivityLevel
,
ConnectivityLoad
,
\
...
@@ -107,6 +109,39 @@ def fetch_data_from_table(table_model, extract_function):
...
@@ -107,6 +109,39 @@ def fetch_data_from_table(table_model, extract_function):
return
[]
return
[]
def
fetch_data_from_table_with_user_category
(
table_model
,
extract_function
):
distinct_years
=
(
db
.
session
.
query
(
distinct
(
table_model
.
year
))
.
order_by
(
table_model
.
year
.
asc
())
.
all
()
)
result
=
[]
for
years
,
user_category
in
product
(
distinct_years
,
UserCategory
):
year
=
years
[
0
]
entries
=
(
db
.
session
.
query
(
NREN
,
year
,
table_model
)
.
outerjoin
(
table_model
,
and_
(
NREN
.
id
==
table_model
.
nren_id
,
table_model
.
year
==
year
,
user_category
==
table_model
.
user_category
))
.
order_by
(
NREN
.
name
.
asc
())
.
all
()
)
for
nren
,
year
,
entry_model
in
entries
:
if
entry_model
is
None
:
# Placeholder entry
data
=
{
'
nren
'
:
nren
.
name
,
'
nren_country
'
:
nren
.
country
,
'
year
'
:
year
,
'
user_category
'
:
user_category
.
value
,
}
else
:
data
=
extract_function
(
nren
,
year
,
entry_model
)
result
.
append
(
data
)
return
result
def
extract_model_data
(
nren
,
year
,
entry_model
):
def
extract_model_data
(
nren
,
year
,
entry_model
):
if
isinstance
(
entry_model
,
DarkFibreLease
):
if
isinstance
(
entry_model
,
DarkFibreLease
):
return
{
return
{
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/routes/data_download.py
+
9
−
8
View file @
7444ac66
...
@@ -14,7 +14,8 @@ from compendium_v2.db.presentation_models import AlienWave, BudgetEntry, Capacit
...
@@ -14,7 +14,8 @@ from compendium_v2.db.presentation_models import AlienWave, BudgetEntry, Capacit
Standards
,
SubOrganization
,
TrafficRatio
,
TrafficStatistics
,
\
Standards
,
SubOrganization
,
TrafficRatio
,
TrafficStatistics
,
\
TrafficVolume
,
Policy
,
WeatherMap
TrafficVolume
,
Policy
,
WeatherMap
from
compendium_v2.routes
import
common
from
compendium_v2.routes
import
common
from
compendium_v2.routes.common
import
extract_model_data
,
extract_special_model_data
,
fetch_data_from_table
from
compendium_v2.routes.common
import
extract_model_data
,
extract_special_model_data
,
fetch_data_from_table
,
\
fetch_data_from_table_with_user_category
from
flask
import
Blueprint
from
flask
import
Blueprint
routes
=
Blueprint
(
'
data_download
'
,
__name__
)
routes
=
Blueprint
(
'
data_download
'
,
__name__
)
...
@@ -45,23 +46,23 @@ def fetch_and_combine_data() -> Sequence[Optional[Dict[str, Any]]]:
...
@@ -45,23 +46,23 @@ def fetch_and_combine_data() -> Sequence[Optional[Dict[str, Any]]]:
result_set
.
append
({
'
name
'
:
'
Commercial Charging Level
'
,
'
data
'
:
entries
})
result_set
.
append
({
'
name
'
:
'
Commercial Charging Level
'
,
'
data
'
:
entries
})
# Fetch and extract data from the ConnectedProportion table and add it to the result set
# Fetch and extract data from the ConnectedProportion table and add it to the result set
entries
=
fetch_data_from_table
(
ConnectedProportion
,
extract_model_data
)
entries
=
fetch_data_from_table
_with_user_category
(
ConnectedProportion
,
extract_model_data
)
result_set
.
append
({
'
name
'
:
'
Market Share
'
,
'
data
'
:
entries
})
result_set
.
append
({
'
name
'
:
'
Market Share
'
,
'
data
'
:
entries
})
# Fetch and extract data from the ConnectivityLevel table and add it to the result set
# Fetch and extract data from the ConnectivityLevel table and add it to the result set
entries
=
fetch_data_from_table
(
ConnectivityLevel
,
extract_model_data
)
entries
=
fetch_data_from_table
_with_user_category
(
ConnectivityLevel
,
extract_model_data
)
result_set
.
append
({
'
name
'
:
'
Level of IP Connectivity
by Institution Type
'
,
'
data
'
:
entries
})
result_set
.
append
({
'
name
'
:
'
Level of IP Connectivity
'
,
'
data
'
:
entries
})
# Fetch and extract data from the ConnectionCarrier table and add it to the result set
# Fetch and extract data from the ConnectionCarrier table and add it to the result set
entries
=
fetch_data_from_table
(
ConnectionCarrier
,
extract_model_data
)
entries
=
fetch_data_from_table
_with_user_category
(
ConnectionCarrier
,
extract_model_data
)
result_set
.
append
({
'
name
'
:
'
Methods of
Carrying IP Traffic to Users
'
,
'
data
'
:
entries
})
result_set
.
append
({
'
name
'
:
'
Carrying IP Traffic to Users
'
,
'
data
'
:
entries
})
# Fetch and extract data from the ConnectivityLoad table and add it to the result set
# Fetch and extract data from the ConnectivityLoad table and add it to the result set
entries
=
fetch_data_from_table
(
ConnectivityLoad
,
extract_model_data
)
entries
=
fetch_data_from_table
_with_user_category
(
ConnectivityLoad
,
extract_model_data
)
result_set
.
append
({
'
name
'
:
'
Traffic Load
'
,
'
data
'
:
entries
})
result_set
.
append
({
'
name
'
:
'
Traffic Load
'
,
'
data
'
:
entries
})
# Fetch and extract data from the ConnectivityGrowth table
# Fetch and extract data from the ConnectivityGrowth table
entries
=
fetch_data_from_table
(
ConnectivityGrowth
,
extract_model_data
)
entries
=
fetch_data_from_table
_with_user_category
(
ConnectivityGrowth
,
extract_model_data
)
result_set
.
append
({
'
name
'
:
'
Est Traffic Growth 3 years
'
,
'
data
'
:
entries
})
result_set
.
append
({
'
name
'
:
'
Est Traffic Growth 3 years
'
,
'
data
'
:
entries
})
# Fetch and extract data from the CommercialConnectivity table and add it to the result set
# Fetch and extract data from the CommercialConnectivity table and add it to the result set
...
...
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