From 06afb118d7d68d56953eef319c897ccb9c4c0d16 Mon Sep 17 00:00:00 2001 From: "Jeison Yehuda Amihud (Blender Dumbass)" Date: Tue, 13 Jun 2023 18:18:42 +0000 Subject: [PATCH] Made analytics more sensitive to text lengths in the scenes. It was jumping a little bit back every time I added a new shot. And it always offsetting my daily percentage since it is much more sensitive to smallest changes. I hope this fixes it. --- studio/story.py | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/studio/story.py b/studio/story.py index abd59fc..56397a7 100644 --- a/studio/story.py +++ b/studio/story.py @@ -675,7 +675,9 @@ def load(project): for scenename in data["scenes"]: shotsfractions = [] + shotslengths = [] textlength = 0 + prevtextpos = 0 for shot in data["scenes"][scenename]["shots"]: for t in shot[-1]: textlength = textlength + len(t[-1]) @@ -711,18 +713,44 @@ def load(project): elif len(os.listdir(folder+"/extra")) > 0: shotsfractions.append(0.2) except: - shotsfractions.append(0.0) + shotsfractions.append(0.0) + + shotslengths.append( textlength - prevtextpos ) + prevtextpos = textlength + + # Adjusting fractions based on the length of the text marked. + + lastlen = 0 + for t in data["scenes"][scenename]["shots"][-1][-1]: + lastlen = lastlen + len(t[-1]) + + + try: + avgtxtlng = sum(shotslengths) / len(shotslengths) + except: + avgtxtlng = 1 + + avgtxtlng = min(1, avgtxtlng) + + sf = [] + for n, i in enumerate(shotsfractions): + try: + l = shotslengths[n] + except: + l = 0 + nf = l / (textlength - lastlen) * i + + sf.append(nf) + # If the last block isn't shot_block. It's safe to assume that # not all of the shots are yet marked in the text. Therefor we # want to estimate how much is marked. multiply_by = 1 if not data["scenes"][scenename].get("no_more_shots") and data["scenes"][scenename]["shots"][-1][0] == "text_block": - lastlen = 0 - for t in data["scenes"][scenename]["shots"][-1][-1]: - lastlen = lastlen + len(t[-1]) + try: multiply_by = (textlength - lastlen) / textlength except: @@ -731,7 +759,7 @@ def load(project): try: data["scenes"][scenename]["fraction"] = \ - ( sum(shotsfractions) / len(shotsfractions) ) * multiply_by + ( sum(sf) ) * multiply_by except: data["scenes"][scenename]["fraction"] = 0.0 @@ -757,7 +785,7 @@ def load(project): # FINAL STUFF... - try: + try: data["fraction"] = sum(fractions) / len(fractions) except: data["fraction"] = 0.0