Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ReadWriteExcel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sukanya K
ReadWriteExcel
Commits
5b4e287d
Commit
5b4e287d
authored
3 months ago
by
Sukanya K
Browse files
Options
Downloads
Patches
Plain Diff
first commit
parent
25187083
No related branches found
No related tags found
No related merge requests found
Changes
42
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
utils/payload_mapping.py
+46
-0
46 additions, 0 deletions
utils/payload_mapping.py
utils/unpack_data.py
+25
-0
25 additions, 0 deletions
utils/unpack_data.py
with
71 additions
and
0 deletions
utils/payload_mapping.py
0 → 100644
+
46
−
0
View file @
5b4e287d
# # utils/payload_mapping.py
#
# def get_payload_mapping(cefr_level, scenario, scenario_question, subject, email_content):
# """
# Maps input data to the payload structure required by the API with fixed user_id, question_id, and answer_id.
#
# Args:
# cefr_level (str): The CEFR level of the input data.
# scenario (str): The scenario description.
# scenario_question (str): The scenario question.
# subject (str): The subject or topic.
# email_content (str): The email content.
#
# Returns:
# dict: The payload ready to be sent to the API.
# """
# return {
# "cefr_level": cefr_level,
# "user_id": 7600001, # Static user ID
# "question_id": 100456, # Static question ID
# "answer_id": 120000789, # Static answer ID
# "scenario": scenario,
# "scenario_question": scenario_question,
# "subject": subject,
# "email_content": email_content
# }
from
config
import
PAYLOAD_FIELDS_STATIC
def
get_payload_mapping
(
input_data
):
"""
Maps input data to the payload structure required by the API dynamically.
Args:
input_data (dict): The dictionary containing dynamically unpacked input data.
Returns:
dict: The complete payload ready to be sent to the API.
"""
# Start with manually configured static fields from config.json
payload
=
PAYLOAD_FIELDS_STATIC
.
copy
()
# Ensuring we don't modify the original dictionary
# Add dynamically unpacked fields
payload
.
update
(
input_data
)
return
payload
This diff is collapsed.
Click to expand it.
utils/unpack_data.py
0 → 100644
+
25
−
0
View file @
5b4e287d
from
config
import
INPUT_FIELDS_DYNAMIC
from
utils.payload_mapping
import
get_payload_mapping
def
unpack_input_data
(
input_data
):
"""
Unpacks input data dynamically using JSON-defined mappings.
Args:
input_data (dict): The dictionary containing raw input data (e.g., from Excel).
Returns:
dict or None: The prepared payload for the API request or None if the row is empty.
"""
unpacked_data
=
{}
# Loop through INPUT_FIELDS mapping from config.json to dynamically unpack data
for
excel_field
,
payload_key
in
INPUT_FIELDS_DYNAMIC
.
items
():
unpacked_data
[
payload_key
]
=
input_data
.
get
(
excel_field
,
""
).
strip
()
# Strip whitespace
# Check if all unpacked values are empty
if
all
(
value
==
""
for
value
in
unpacked_data
.
values
()):
return
None
# Skip empty rows
# Pass valid data to get_payload_mapping
return
get_payload_mapping
(
unpacked_data
)
This diff is collapsed.
Click to expand it.
Prev
1
2
3
Next
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