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