animation_tools.py
A group of functions that work with css_tools and cascade_tools to provide reports on CSS animations.
get_animation_properties_report(project_folder, num_goal, specific_properties=None)
returns a list of pass/fail messages based on number and type of unique animation keyframe properties.
You can specify just the number of unique properties or you can specify both the number as well as check for specific targetted properties. If you specify both, both must be met for a pass.
NOTE: In the case of the transform properties, you can just specify transform, or you can include the type of transform in the form of transform- + the transform value (eg. transform-rotate(), transform-translate(), transfrom-skew(), etc.)
Since animation_values might have multiple entries for the same file, we need to track a per file record to see if it meets or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
animation_values
|
a list of filenames with keyframe and property data. |
required | |
num_goal
|
int
|
the minimum number of percentage keyframes we would want to see. |
required |
specific_properties
|
a list or tuple of properties required to be present. |
None
|
Returns:
Name | Type | Description |
---|---|---|
results |
list
|
a list of messages (one for each file in the project) with a pass or fail with number present of each type. |
Source code in webcode_tk/animation_tools.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
get_animation_report(project_dir)
gets a report on the implementation of animation in a project.
The animation report should contain a single entry for each HTML file. Each HTML file will have a list of animations: the name of the keyframe, a list of each keyframe type (percentage, from, or two), and a list of properties included and if it is transform, it will treat each type of transform as a unique property: eg. skew(), rotate(), translate(), etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_dir
|
str
|
the path to the project folder. |
required |
Returns:
Name | Type | Description |
---|---|---|
report |
list
|
a list of dictionary objects |
Source code in webcode_tk/animation_tools.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
get_keyframe_data(report)
return a list of keyframe types and numbers from an animation report
The goal is to track all data related to animation keyframes per file. The data is a dictionary of filenames. The filenames will be the key, and each filename's values will be a dictionary of keyframe names, number of percentage keyframes, and the number of from {} and to {} keyframes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
report
|
list
|
an animation report, which is a list of project files with a dictionary of details |
required |
Returns:
Name | Type | Description |
---|---|---|
data |
dict
|
a dictionary of filenames as primary keys with a dictionary of keyframe data as the key's value. |
Source code in webcode_tk/animation_tools.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
get_keyframe_report(project_folder, num_goal, pct_goal=None, from_to_goals=None)
returns a list of pass/fail messages (1 for each goal in each file).
A report that allows you to set the minimum number of keyframes for each file. By setting num_goal, you are stating how many keyframes in all you expect to see in a project.
You can also set a minimum number of percentage keyframes, and the minimum number of from {} and to {} keyframes.
NOTE: for every goal, there will be a report on that goal (one for each file). If your project has two files, and you set all three goals ( num_goal, pct_goal, and from_to_goals), the report will create a list of 6 messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_folder
|
str
|
the folder that houses the project. |
required |
num_goal
|
int
|
the minimum number of keyframes per file (overall) |
required |
pct_goal
|
the minimum number of percentage keyframes we would want to see. |
None
|
|
from_to_goals
|
the minimum number of from and to keyframes. |
None
|
Returns:
Name | Type | Description |
---|---|---|
results |
list
|
a list of messages (one for each file in the project) with a pass or fail with number present of each type. |
Source code in webcode_tk/animation_tools.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
get_num_properties_msg(num_goal, properties_targetted, current_file)
Returns a pass/fail message based on whether a file targets the min number of properties found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_goal
|
int
|
the number of unique properties that should be targetted |
required |
Source code in webcode_tk/animation_tools.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
get_targetted_properties_msg(properties, properties_targetted, current_file)
returns whether the file addresses all targetted keyframe properties or not.
Receives the keyframe properties found in a file's styles and returns a message that states whether the file has targetted all required properties in the form of "pass" or "fail".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
properties
|
Union[list, tuple]
|
a list or tuple of the keyframe properties targetted in a file's stylesheets or not. |
required |
properties_targetted
|
Union[list, tuple]
|
a list or tuple of the properties that the file should contain. |
required |
current_file
|
str
|
the name of the HTML document we are checking. |
required |
Returns:
Name | Type | Description |
---|---|---|
msg |
str
|
a string that begins with 'pass:' or 'fail:', and details on what was missing if a fail. |
Source code in webcode_tk/animation_tools.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
Notes
I added these tools to check CSS animations. In my class, my more advanced students are learning to make keyframe animations, and I want to test to make sure they have a certain number of keyframes, and be able to check whether they are using from {}
and to {}
keyframes as well as percentage keyframes.
I would also like to encourage them to animate more than use standard properties, but to target transforms.