Data Types and Methods
Basic Data Types
Type | Icon | Description |
---|---|---|
Value | ![]() | Values can be of any type, including String, Number, DateTime, Bool, and Entity. |
Dict | ![]() | Keys can be either Value, List, or Set, and their length must not exceed 10 characters. The associated values can be of any type. |
List | ![]() | Elements within a List can be of any type. |
Value types
Value types will only appear in the formula prompt within the formula bar.
Type | Icon |
---|---|
String | ![]() |
Number | ![]() |
Datetime | ![]() |
Bool | ![]() |
Entity | ![]() |
Entity types
Entity types will only appear in the formula prompt within the formula bar.
Type | Icon |
---|---|
Agent | ![]() |
Cell | ![]() |
Link | ![]() |
Data Object Methods
Method Name | Description | Applicable Data Type | Parameter 1 | Parameter 2 | Does it modify the original object |
---|---|---|---|---|---|
delete | Delete an element at a specified index, return the modified original object | List, Dict | index: Int / key: Value | ||
remove | Delete a specified value, return the modified original object | List, Set | value: Any | ||
merge | Merge dictionaries, return the modified original object | Dict | dicts: Dict, Dict, ... | ||
sub | Obtain a sub-dictionary using a list of indices | Dict | keys list: [Value/List/Set] | ||
sub | Create a sub-list from a list of indices. | List | indexes list: [Int] | ||
sub | Extract a substring based on a specified position and length. | String | position: Int | length: Int | |
extend | Merge lists and return the modified original object. | List | lists: List, List, ... | ||
append | Append a value to the end of a list and return the modified original object. | List | value: Any, Any, ... | ||
insert | Insert a value at a certain index in a list and return the modified original object. | List | position: Int | value: Any | |
insert | Add a value to a set and return the modified original object. | Set | value: Any | ||
find | Find the first index of the specified value in the list | List | value: Any | ||
join | Join the elements of a list into a string using a specified delimiter | List | seperator: String | ||
contains | Check if a List contains a specific element | List | value: Any | ||
contains | Check if a Dict has a specific key | Dict | key: Any | ||
contains | Check if a String includes a specific substring | String | str: String | ||
split | Split a string into a list using a specified character | String | seperator: String | ||
replace | Replace all occurrences of old with new in a string, and return a new string | String | old: String | new: String | |
upper | Convert a string to uppercase | String | value: String | ||
lower | Convert a string to lowercase | String | value: String | ||
sort | Sort a list in order, returning a new sorted object. | List | sort ascending: True | by=None / lambda | |
except | Remove all elements that appear in the given List or Set from the original List or Set object, and return the modified original object. | List, Set | exclude value: List / Set | ||
choice | Randomly choose a value from a list or set | List, Set | |||
pop | Randomly pop an element from a list or set | List, Set | |||
shuffle | Randomly rearranges the order of elements in a List | List | |||
copy | Copy an object | any | |||
add | Move time forward | DateTime | delta:Number | unit='s':String, can be: "d", "h", "m", "s" | |
minus | Move time backward | DateTime | delta:Number | unit='s':String, can be: "d", "h", "m", "s" | |
delta | Calculate the difference between two datetime | DateTime | t2: DateTime | unit='s':String, can be: "d", "h", "m", "s" | |
timestamp | Get the timestamp in seconds | DateTime |
Method Usage
-
Input formulas or expressions in the following format:
data_object_name.method()
. -
About the
List_object.sort
methodSince the system supports using a lambda function for the second parameter (sorting criteria), advanced sorting can be performed on Lists where elements are in Entity, Dict, or List type.
Suppose each student has scores for three courses, and you want to sort the students by their scores. The rule is to first sort by the weighted sum of Math (weight 0.7) and Physics (weight 0.3) scores. If the sums are the same, then sort by Biology scores in descending order.
-
If the three scores are three properties of an Agent, you can try the following expression to achieve multi-level sorting of Student Agent individuals:
Student.Individuals.copy().sort(False, by=lambda x: [x.Math * 0.7 + x.Physics * 0.3, x.Biology])
-
If student data is stored in a List variable named
Students
with the element format{"Name": <String>, "Math": <Number>, "Physics": <Number>, "Biology": <Number>}
, then you can try the following expression to achieve multi-level sorting of the student List:Students.sort(False, by=lambda x: [x["Math"] * 0.7 + x["Physics"] * 0.3, x["Biology"]])
-
If student data is stored in a List variable named
Students
with the element format[Name<String>, Math<Number>, Physics<Number>, Biology<Number>]
, then you can try the following expression to achieve multi-level sorting of the student List:Students.sort(False, by=lambda x: [x[1] * 0.7 + x[2] * 0.3, x[3]])