• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to Change property based on csv column data. Make green text for fastest lap expression

Participant ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

I have created a car race timing sheet animation. Basically a table with top 10 cars their finishing positions, time, no. Of laps, fastest lap, behind in seconds etc

I have linked the source text for table to a csv so I can update easily for races throughout the season. I’ve worked all that out.

I would like to change properties based on particular column data. E.g change colour of text for the fasted lap.

I’m having a bit of difficulty with that.

Can someone assist with an expression or resource I can use to help me achieve this.

TOPICS
Expressions

Views

395

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Apr 17, 2021 Apr 17, 2021

SO I solved this - I'll put the code here so that if anyone ever wants to do the same there is some help here - note: I am not a programmer and just learnign expressions so it may not be the most efficient way to do this.

 

//highlights fastest lap in green can be used on any colour field
//e.g. use a fill on a txt layer displaying the data to highlight
//Important - name the layer according to the data heading 
//i.e. Fastest Lap 0 , Fastest Lap 1 , ... Fastest Lap 9

csvname = Race Results.csv /
...

Votes

Translate

Translate
Participant ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

SO I solved this - I'll put the code here so that if anyone ever wants to do the same there is some help here - note: I am not a programmer and just learnign expressions so it may not be the most efficient way to do this.

 

//highlights fastest lap in green can be used on any colour field
//e.g. use a fill on a txt layer displaying the data to highlight
//Important - name the layer according to the data heading 
//i.e. Fastest Lap 0 , Fastest Lap 1 , ... Fastest Lap 9

csvname = Race Results.csv //csv filename
rowname = thisLayer.name ; 
colname = rowname.slice(0,rowname.lastIndexOf(" ")); //Changes string from "Fastest Lap 0" to "Fastest Lap"
datanum = thisComp.layer(csvname)("Data")("Outline")(colname)(rowname);

//This code iterates through the column data and adds each datapoint to an array
values = [];
for(i=0;i<=thisComp.layer(csvname)("Data")("Number of Rows")-1;i++) {   
  values.push(thisComp.layer(csvname)("Data")("Outline")(colname)(colname + " " + i).value); 
}
fastlap = Math.min.apply(null, values)//Finds the Minimum Value in the array

if (fastlap == datanum) { [0.02353,1,0,1] }
//If the datapoint in this column & row is the same as the minimum value in the column make green
else
[1,1,1,1];
//If the datapoint is not the minimum make white

This expression uses to highlight the best lap consistencty. In the csv the data is not a number but a string like "99.45%". This expression makes it work by stripping of the "%" sign and thenm uses the numbers to work out if is the maximum consistency, whereas Fastest Lap is the minimum.

//highlights highest lap consistency in green can be used on any colour field
//e.g. use a fill on a txt layer displaying the data to highlight
//Consistency Data is in a string "99.45%" this expression converts the string to a number "99.45"
//Important - name the layer according to the data heading 
//i.e. Consistency 0 , Consistency 1 , ... Consistency 9

csvname = Race Results.csv //csv filename
rowname = thisLayer.name ;
colname = rowname.slice(0,rowname.lastIndexOf(" "));
datatxt = thisComp.layer(csvname)("Data")("Outline")(colname)(rowname);
datanum = datatxt.slice(0,5);//Convert this layers datapoint to a num

//This code iterates through the column data converst string to num and adds each datapoint to an array
values = [];
for(i=0;i<=thisComp.layer(csvname)("Data")("Number of Rows")-1;i++) {   
  values.push(thisComp.layer(csvname)("Data")("Outline")(colname)(colname + " " + i).value.slice(0,5)); 
}
bestconsi = Math.max.apply(null, values)

if (bestconsi == datanum) { [0.02353,1,0,1] }
//If the datapoint in this column & row is the same as the minimum value in the column make green
else
[1,1,1,1];
//If the datapoint is not the minimum make white

This expression I use so that I can name the text layer and it uses that to grab the data from the csv.

//in a txt layer - add to Source Text field
//Uses the layer name to get the data from a csv for
//add csv to comp, each column has a heading - use that heading a space then datapoint number as layer name
//i.e. csv is "Race Results.csv" Column is "Names" I want the 4th row therefore name layer "Names 3"

csvname = Race Results.csv //csv filename
rowname = thisLayer.name ;
colname = rowname.slice(0,rowname.lastIndexOf(" "));

thisComp.layer(csvname)("Data")("Outline")(colname)(rowname);

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

LATEST

it won't let me edit the code above but for all the expressions where it says:

 

csvname = Race Results.csv

 

should read

 

csvname = "Race Results.csv"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines