degrees.py
Overview
The degrees.py module provides a simple lookup utility for mapping between educational degree identifiers (IDs) and their corresponding degree names. It includes predefined mappings for various academic degrees, primarily in Chinese and English, and offers two straightforward functions to convert from ID to name and vice versa.
This file is designed to serve as a centralized reference for degree codes used within the larger InfiniFlow system, enabling consistent and error-free translation between numeric/string codes and human-readable degree names. It is useful in contexts such as user profiles, academic records, or any component where degree information needs to be normalized or validated.
Classes and Functions
This module does not define any classes; it only contains constants and functions.
Constants
TBL
Type:
dict[str, str]Description: A dictionary mapping degree IDs (as strings) to their respective degree names. The keys are string representations of numeric codes, and the values are degree names, including both Chinese names and English abbreviations.
Example entries:
"94": "EMBA""3": "博士"(Doctorate)"1": "本科"(Undergraduate)
TBL_
Type:
dict[str, str]Description: The inverse mapping of
TBL. It maps degree names (converted to uppercase) back to their corresponding IDs as strings. This is generated programmatically by reversing the key-value pairs ofTBL.Purpose: Enables quick lookup of the degree ID by degree name.
Functions
get_name(id)
def get_name(id: str) -> str:
Purpose: Retrieves the degree name corresponding to the given degree ID.
Parameters:
id(stror any type coercible to string): The degree ID whose name is to be looked up.
Returns:
str- The degree name if found; otherwise, an empty string"".Behavior:
Converts the
idto a string and looks it up in theTBLdictionary.Returns an empty string if the ID is not present.
Usage Example:
>>> get_name("3")
'博士'
>>> get_name(94)
'EMBA'
>>> get_name("999")
''
get_id(nm)
def get_id(nm: str) -> str:
Purpose: Retrieves the degree ID corresponding to the given degree name.
Parameters:
nm(str): The degree name to look up.
Returns:
str- The degree ID as a string if found; otherwise, an empty string"".Behavior:
Returns an empty string if
nmisNoneor an empty string.Converts
nmto uppercase and strips whitespace before looking up inTBL_.Returns an empty string if the name is not present.
Usage Example:
>>> get_id("博士")
'3'
>>> get_id("MBA")
'6'
>>> get_id("mba") # Case insensitive due to upper()
'6'
>>> get_id("Unknown Degree")
''
Implementation Details
The mappings are stored in dictionaries (
TBLandTBL_) for O(1) average-time complexity lookups.TBL_is generated once at module load time by invertingTBLusing a dictionary comprehension.Degree names in
TBL_keys are stored in uppercase to support case-insensitive lookups inget_id.The functions handle missing or invalid inputs gracefully by returning empty strings rather than raising exceptions.
System Interaction
This module likely serves as a utility or helper within the InfiniFlow system, used by components that handle user or academic data.
Other parts of the system can import this file to standardize degree information representation.
It does not depend on external modules or resources, making it a lightweight and easily reusable component.
Could be used in:
User profile management (to map degree codes to display names)
Data validation during input or import processes
Reporting or exporting academic qualification data
Diagram: Module Function Flow
flowchart TD
A[get_id(nm)] -->|Uses| B[TBL_ Dictionary]
C[get_name(id)] -->|Uses| D[TBL Dictionary]
subgraph Dictionaries
B
D
end
style Dictionaries fill:#f9f,stroke:#333,stroke-width:1px
Summary
The degrees.py file is a focused utility module within the InfiniFlow project that provides straightforward mappings between degree IDs and degree names. It ensures consistent interpretation of academic degree codes across the system with minimal overhead and simple API functions.
End of degrees.py documentation