katelynnm 1 Posted November 7, 2013 Report Share Posted November 7, 2013 (edited) I have a table with 50 rows (a screencap of part of it is below). I have another csv file that states how many visits a writer averages on his/her posts. Basically I need to set a variable called #rate that will correspond to the range that the person falls under. For instance, if the person averages 200 visits per post, then #rate will equal $1.50. I need it to loop through a csv of users to calculate each one and add them all to a new list. I'm not sure how to go about it without manually setting each range as a separate if statement, and I feel like there must be a smarter and easier way than that. Does anyone have any ideas? http://i39.tinypic.com/mj766x.jpg Edited November 11, 2013 by katelynnm Quote Link to post Share on other sites
bestmacros 60 Posted November 7, 2013 Report Share Posted November 7, 2013 another solution would be creating csv table with scores and values just like you have on the picture.load csv to table and compare each user's score with 1st column values in loop using logic: score is bigger than cell A (row X column 1) but less than cell B (row X+1 column 1) if true - take value from column 2 row A, increment X each time Quote Link to post Share on other sites
LazyBotter 188 Posted November 7, 2013 Report Share Posted November 7, 2013 Do you have an example csv? Other than the pic? Quote Link to post Share on other sites
ds062692 19 Posted November 7, 2013 Report Share Posted November 7, 2013 I think this should work for you. The idea is that the range is not important but the lowest qualifying visit count for a specific rate is. For example it does not matter if there were 1500 visits or 1599, it would still be the same rate. You can use the javascript math floor function, it rounds down to the nearest integer. 1.5 -> 1, 7.43 -> 7. First it makes the average visitor into a decimal by dividing by 100. 345 will equal 3.45. Than the eval will round it down to 3 which get multiplied by 100 again to get the lower range. Which you can then compare with the values from the compensation chart. I used a not contains, but in this case a comparison will be better, just make sure you are comparing a number to a number, remove the plus sign when comparing. I hope this made sense. set(#decimal, $divide(#averageVisits, 100), "Global") set(#value, $multiply($eval("Math.floor({#decimal})"), 100), "Global") set(#value counter, 0, "Global") loop while($not($contains($table cell(&table, #value counter, 0), #value))) { increment(#value counter) } set(#rate, $table cell(&table, #value counter, 1), "Global") 1 Quote Link to post Share on other sites
k1lv9h 76 Posted November 8, 2013 Report Share Posted November 8, 2013 Hi, Sample code for table search to find rate:sample-table-rate-lookup-001.ubot Updated sample code: Fixed beyond table range logic. Kevin Quote Link to post Share on other sites
katelynnm 1 Posted November 11, 2013 Author Report Share Posted November 11, 2013 Thank you all so much for all of the help!! Sorry I wasn't able to respond sooner-I was out of town. ds062692-that seemed to do the trick-it's working great now! Thanks again! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.