Author

Topic: [BOUNTY 0.03 BTC] Looking for someone to translate a simple algo into bash (Read 1343 times)

hero member
Activity: 800
Merit: 1000
legendary
Activity: 1092
Merit: 1001
Perfect! Awesome job, 0.05 BTC reward sent!

6e8cb37bcac2b6f182a95d3cab3f2a6894f74699983d85c1c50d9ed9a25f13a7

hero member
Activity: 800
Merit: 1000
Code:
#!/usr/bin/env python
import xlrd
import sys

if len(sys.argv) < 0:
   print("XLS File Not Specified")
   sys.exit(-1)

file = sys.argv[1]
print("--------------------------------------------------------------------------")
print("Loading XLS File: {0}".format(file))
print("--------------------------------------------------------------------------")

stats = {0: {'Count': 0, 'Total': 0}, 1: {'Count': 0, 'Total': 0}}
required_values = ['por', 'ds', 'dc', 'dd', 'mcc', 'dscs', 'ddcd', 'ddcddscs', 'dsdc', 'dddc', 'dsdddc', 'dddscdcs', 'dsdccs']
other_values = ['dc', 'ds', 'dd', 'cd', 'cs']
ignored_cells = []

def load_sheet(file, sheet):
    workbook = xlrd.open_workbook(file)
    worksheet = workbook.sheet_by_index(0)
    return worksheet

def read_stats(start_row, end_row, stats={'Count': 0, 'Total': 0}):
    for i in range(start_row, end_row):
if i+1 in ignored_cells:
  continue

value = sheet.cell(i, 0).value
if value.lower() in required_values or any(item in value.lower() for item in other_values):
           amount = sheet.cell(i, 3).value
  if type(amount) == unicode and amount.strip() == '-':
     amount = float(0)
           if type(amount) != float and not amount.isdigit():
              amount = amount.replace(',', '.')
              amount = float(amount)
           stats['Count'] += 1
           stats['Total'] += amount
           print("Column A{0}. Key: {1}. Incrementing Counter and adding value: {2}".format(i+1, value, amount))

while True:
   print("Question 1: ")
   ignored_cell = raw_input()
   if not ignored_cell.isdigit():
print("Value was not a number")
continue
   ignored_cell = int(ignored_cell)
   if ignored_cell == 0:
break
   if ignored_cell > 23 or ignored_cell < 0:
print("Number Out of Range")
continue
   print("Ignoring Cell: {0}".format(ignored_cell))
   ignored_cells.append(ignored_cell)

print("--------------------------------------------------------------------------")
print("Ignoring Cells: {0}".format(",".join((str(i) for i in ignored_cells))))
sheet = load_sheet(file, 0)

print("--------------------------------------------------------------------------")
print("Reading Team 1 Stats: Rows 1, 11")
print("--------------------------------------------------------------------------")
read_stats(0, 11, stats[0])
print("--------------------------------------------------------------------------")
print("Reading Team 2 Stats: Rows 13 - 23")
print("--------------------------------------------------------------------------")
read_stats(12, 23, stats[1])

difference = stats[0]['Count'] - stats[1]['Count']
if difference > 0:
   stats[1]['Total'] += (5 * difference)
   print("Difference is Negative, Adding 5 * {0} to Team 1".format(difference))
elif difference < 0:
   stats[0]['Total'] += (5 * -difference)
   print("Difference is Negative, Adding 5 * {0} to Team 0".format(-difference))


print("--------------------------------------------------------------------------")
print("Team One Total: {0}".format(stats[0]['Total']))
print("Team Two Total: {0}".format(stats[1]['Total']))
print("Team Difference: {0}".format(stats[0]['Total'] - stats[1]['Total']))
print("--------------------------------------------------------------------------")

Fixed in that one
legendary
Activity: 1092
Merit: 1001
Spotted that and corrected by my own!
Last thing: if I type N in the question, cell A(N+1) gets ignored (I am not able to ignore cell A1).
hero member
Activity: 800
Merit: 1000
my bad

Update it with this

Code:
#!/usr/bin/env python
import xlrd
import sys

if len(sys.argv) < 0:
   print("XLS File Not Specified")
   sys.exit(-1)

file = sys.argv[1]
print("--------------------------------------------------------------------------")
print("Loading XLS File: {0}".format(file))
print("--------------------------------------------------------------------------")

stats = {0: {'Count': 0, 'Total': 0}, 1: {'Count': 0, 'Total': 0}}
required_values = ['por', 'ds', 'dc', 'dd', 'mcc', 'dscs', 'ddcd', 'ddcddscs', 'dsdc', 'dddc', 'dsdddc', 'dddscdcs', 'dsdccs']
other_values = ['dc', 'ds', 'dd', 'cd', 'cs']
ignored_cells = []

def load_sheet(file, sheet):
    workbook = xlrd.open_workbook(file)
    worksheet = workbook.sheet_by_index(0)
    return worksheet

def read_stats(start_row, end_row, stats={'Count': 0, 'Total': 0}):
    for i in range(start_row, end_row):
if i in ignored_cells:
   continue

value = sheet.cell(i, 0).value
if value.lower() in required_values or any(item in value.lower() for item in other_values):
           amount = sheet.cell(i, 3).value
   if type(amount) == unicode and amount.strip() == '-':
      amount = float(0)
           if type(amount) != float and not amount.isdigit():
              amount = amount.replace(',', '.')
              amount = float(amount)
           stats['Count'] += 1
           stats['Total'] += amount
           print("Column A{0}. Key: {1}. Incrementing Counter and adding value: {2}".format(i+1, value, amount))

while True:
   print("Question 1: ")
   ignored_cell = raw_input()
   if not ignored_cell.isdigit():
print("Value was not a number")
continue
   ignored_cell = int(ignored_cell)
   if ignored_cell == 0:
break
   if ignored_cell > 23 or ignored_cell < 0:
print("Number Out of Range")
continue
   print("Ignoring Cell: {0}".format(ignored_cell))
   ignored_cells.append(ignored_cell)

print("--------------------------------------------------------------------------")
print("Ignoring Cells: {0}".format(",".join((str(i) for i in ignored_cells))))
sheet = load_sheet(file, 0)

print("--------------------------------------------------------------------------")
print("Reading Team 1 Stats: Rows 1, 11")
print("--------------------------------------------------------------------------")
read_stats(0, 11, stats[0])
print("--------------------------------------------------------------------------")
print("Reading Team 2 Stats: Rows 13 - 23")
print("--------------------------------------------------------------------------")
read_stats(12, 23, stats[1])

difference = stats[0]['Count'] - stats[1]['Count']
if difference > 0:
   stats[1]['Total'] += (5 * difference)
   print("Difference is Negative, Adding 5 * {0} to Team 1".format(difference))
elif difference < 0:
   stats[0]['Total'] += (5 * -difference)
   print("Difference is Negative, Adding 5 * {0} to Team 0".format(-difference))


print("--------------------------------------------------------------------------")
print("Team One Total: {0}".format(stats[0]['Total']))
print("Team Two Total: {0}".format(stats[1]['Total']))
print("Team Difference: {0}".format(stats[0]['Total'] - stats[1]['Total']))
print("--------------------------------------------------------------------------")
legendary
Activity: 1092
Merit: 1001
Thank you, however I am getting this error when I type a number at the question.

Code:
Question 1: 
2
Traceback (most recent call last):
  File "script.py", line 50, in
    if ignored_cell > 23 or number < 0:
NameError: name 'number' is not defined

Any hint?
hero member
Activity: 800
Merit: 1000
Thank you very much

The script is completed.

My BTC Address is 12tSquEBTgs2WsHXgh5kKD8hNwvsrvo7o1

Running the code on the sample produces

Code:
 ./parse_file.py Workbook1.xlsx 
--------------------------------------------------------------------------
Loading XLS File: Workbook1.xlsx
--------------------------------------------------------------------------
Question 1:
0
--------------------------------------------------------------------------
Ignoring Cells:
--------------------------------------------------------------------------
Reading Team 1 Stats: Rows 1, 11
--------------------------------------------------------------------------
Column A1. Key: Por. Incrementing Counter and adding value: 6.0
Column A2. Key: DsCs. Incrementing Counter and adding value: 5.5
Column A3. Key: Dc. Incrementing Counter and adding value: 5.0
Column A4. Key: Dc. Incrementing Counter and adding value: 6.0
Column A5. Key: DdDsCdCs. Incrementing Counter and adding value: 6.0
Column A7. Key: Mcc. Incrementing Counter and adding value: 6.0
--------------------------------------------------------------------------
Reading Team 2 Stats: Rows 13 - 23
--------------------------------------------------------------------------
Column A13. Key: Por. Incrementing Counter and adding value: 6.0
Column A14. Key: DsDcCs. Incrementing Counter and adding value: 6.0
Column A15. Key: Dc. Incrementing Counter and adding value: 6.0
Column A16. Key: Dc. Incrementing Counter and adding value: 5.0
Column A17. Key: DdDsCdCs. Incrementing Counter and adding value: 5.5
Column A19. Key: Mcc. Incrementing Counter and adding value: 5.0
Column A20. Key: Mcc. Incrementing Counter and adding value: 6.5
Difference is Negative, Adding 5 * 1 to Team 0
--------------------------------------------------------------------------
Team One Total: 39.5
Team Two Total: 40.0
Team Difference: -0.5
--------------------------------------------------------------------------

The code is as follows

Code:
#!/usr/bin/env python
import xlrd
import sys

if len(sys.argv) < 0:
   print("XLS File Not Specified")
   sys.exit(-1)

file = sys.argv[1]
print("--------------------------------------------------------------------------")
print("Loading XLS File: {0}".format(file))
print("--------------------------------------------------------------------------")

stats = {0: {'Count': 0, 'Total': 0}, 1: {'Count': 0, 'Total': 0}}
required_values = ['por', 'ds', 'dc', 'dd', 'mcc', 'dscs', 'ddcd', 'ddcddscs', 'dsdc', 'dddc', 'dsdddc', 'dddscdcs', 'dsdccs']
other_values = ['dc', 'ds', 'dd', 'cd', 'cs']
ignored_cells = []

def load_sheet(file, sheet):
    workbook = xlrd.open_workbook(file)
    worksheet = workbook.sheet_by_index(0)
    return worksheet

def read_stats(start_row, end_row, stats={'Count': 0, 'Total': 0}):
    for i in range(start_row, end_row):
if i in ignored_cells:
  continue

value = sheet.cell(i, 0).value
if value.lower() in required_values or any(item in value.lower() for item in other_values):
           amount = sheet.cell(i, 3).value
  if type(amount) == unicode and amount.strip() == '-':
     amount = float(0)
           if type(amount) != float and not amount.isdigit():
              amount = amount.replace(',', '.')
              amount = float(amount)
           stats['Count'] += 1
           stats['Total'] += amount
           print("Column A{0}. Key: {1}. Incrementing Counter and adding value: {2}".format(i+1, value, amount))

while True:
   print("Question 1: ")
   ignored_cell = raw_input()
   if not ignored_cell.isdigit():
print("Value was not a number")
continue
   ignored_cell = int(ignored_cell)
   if ignored_cell == 0:
break
   if ignored_cell > 23 or number < 0:
print("Number Out of Range")
continue
   print("Ignoring Cell: {0}".format(ignored_cell))
   ignored_cells.append(ignored_cell)

print("--------------------------------------------------------------------------")
print("Ignoring Cells: {0}".format(",".join((str(i) for i in ignored_cells))))
sheet = load_sheet(file, 0)

print("--------------------------------------------------------------------------")
print("Reading Team 1 Stats: Rows 1, 11")
print("--------------------------------------------------------------------------")
read_stats(0, 11, stats[0])
print("--------------------------------------------------------------------------")
print("Reading Team 2 Stats: Rows 13 - 23")
print("--------------------------------------------------------------------------")
read_stats(12, 23, stats[1])

difference = stats[0]['Count'] - stats[1]['Count']
if difference > 0:
   stats[1]['Total'] += (5 * difference)
   print("Difference is Negative, Adding 5 * {0} to Team 1".format(difference))
elif difference < 0:
   stats[0]['Total'] += (5 * -difference)
   print("Difference is Negative, Adding 5 * {0} to Team 0".format(-difference))


print("--------------------------------------------------------------------------")
print("Team One Total: {0}".format(stats[0]['Total']))
print("Team Two Total: {0}".format(stats[1]['Total']))
print("Team Difference: {0}".format(stats[0]['Total'] - stats[1]['Total']))
print("--------------------------------------------------------------------------")
legendary
Activity: 1092
Merit: 1001
Code:
./parse_file.py Workbook1.xlsx 
--------------------------------------------------------------------------
Loading XLS File: Workbook1.xlsx
--------------------------------------------------------------------------
Question 1:
0
--------------------------------------------------------------------------
Ignoring Cells:
--------------------------------------------------------------------------
Reading Team 1 Stats: Rows 1 - 11
--------------------------------------------------------------------------
Column A1. Key: Por. Incrementing Counter and adding value: 6.0
Column A2. Key: DsCs. Incrementing Counter and adding value: 5.5
Column A3. Key: Dc. Incrementing Counter and adding value: 5.0
Column A4. Key: Dc. Incrementing Counter and adding value: 6.0
Column A7. Key: Mcc. Incrementing Counter and adding value: 6.0
--------------------------------------------------------------------------
Reading Team 2 Stats: Rows 13 - 23
--------------------------------------------------------------------------
Column A13. Key: Por. Incrementing Counter and adding value: 6.0
Column A15. Key: Dc. Incrementing Counter and adding value: 6.0
Column A16. Key: Dc. Incrementing Counter and adding value: 5.0
Column A19. Key: Mcc. Incrementing Counter and adding value: 5.0
Column A20. Key: Mcc. Incrementing Counter and adding value: 6.5
--------------------------------------------------------------------------
Team One Total: 28.5
Team Two Total: 28.5
Team Difference: 0
--------------------------------------------------------------------------


Oh man I am so sorry, I forgot to add into the algo DdDsCdCs and DsDcCs. That's why you ain't getting the correct result.
It should add value if the A cell contains a mix of Dc, Ds, Dd, Cd, Cs. All possible combinations amongst these letters must be counted in.

Between we're almost there, very nice job!
hero member
Activity: 800
Merit: 1000
Code:
./parse_file.py Workbook1.xlsx 
--------------------------------------------------------------------------
Loading XLS File: Workbook1.xlsx
--------------------------------------------------------------------------
Question 1:
0
--------------------------------------------------------------------------
Ignoring Cells:
--------------------------------------------------------------------------
Reading Team 1 Stats: Rows 1 - 11
--------------------------------------------------------------------------
Column A1. Key: Por. Incrementing Counter and adding value: 6.0
Column A2. Key: DsCs. Incrementing Counter and adding value: 5.5
Column A3. Key: Dc. Incrementing Counter and adding value: 5.0
Column A4. Key: Dc. Incrementing Counter and adding value: 6.0
Column A7. Key: Mcc. Incrementing Counter and adding value: 6.0
--------------------------------------------------------------------------
Reading Team 2 Stats: Rows 13 - 23
--------------------------------------------------------------------------
Column A13. Key: Por. Incrementing Counter and adding value: 6.0
Column A15. Key: Dc. Incrementing Counter and adding value: 6.0
Column A16. Key: Dc. Incrementing Counter and adding value: 5.0
Column A19. Key: Mcc. Incrementing Counter and adding value: 5.0
Column A20. Key: Mcc. Incrementing Counter and adding value: 6.5
--------------------------------------------------------------------------
Team One Total: 28.5
Team Two Total: 28.5
Team Difference: 0
--------------------------------------------------------------------------
legendary
Activity: 1092
Merit: 1001
I will do it for you in python for 0.05 BTC

Yeah sorry, ive tried everything but i just get different results
Ahmed

Thank you for your efforts, what results are you getting?
hero member
Activity: 800
Merit: 1000
I will do it for you in python for 0.05 BTC

Yeah sorry, ive tried everything but i just get different results
Ahmed
legendary
Activity: 3514
Merit: 1280
English ⬄ Russian Translation Services
But maybe I am confusing bash with something like, what I meant is, I would to like to have a normal text code which I will eventually make it executable with the command chmod and run it with ./command

You are correct, bash is the right thing if you don't need graphical interface (just the console). Let's wait and see if someone agrees to your price (0.05 BTC)

Quote
bash --version
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
legendary
Activity: 1092
Merit: 1001
Hello there, I am currently looking for someone who writes me down a linux bash script which reads from a .xls file and then do some calc.

The task is not as easy as it seems. I guess you should first convert your .xls file to a CSV format (comma separated values) from within Excel (you can export to a .csv file)...

I could do that, but surely not for 0.03 BTC

Xls format is not necessary. I take the table from a web page, so if preferred, I can paste it to a csv file or whatever file format suits the best.

Okay, 0.3 BTC and escrow. The task is not difficult, but you should understand that this is not a monkey business. I have developed sophisticated utilities for importing and exporting csv files (c++/qt, both for Windows and Linux), so it is not quite up to my level, and if you find someone cheaper, then more power to you (and I'm lazy as hell)...

Just curious, why bash?

0.3 BTC is quite too much for my efforts. 0.05 BTC is the  very maximum offer I can reach at the moment.
This a prototype of the web page I will take cells from http://leghe.fantagazzetta.com/fantalega-dei-campioni/formazioni
I would not use an escrow for such low amount of money, I have made several trades in the past and a very recent 1 BTC trade. Everything went smooth, check my trust.
Anyway if you do not feel comfortable with the lack of an escrow feel free to find a reputable one on the forum and give me his contact please.
I ask for bash cause I am on a linux machine and I  would like to see the whole code with having a chance to edit it without the need of installing a compiler or whatever.
But maybe I am confusing bash with something like, what I meant is, I would to like to have a normal text code which I will eventually make it executable with the command chmod and run it with ./command
legendary
Activity: 3514
Merit: 1280
English ⬄ Russian Translation Services
Hello there, I am currently looking for someone who writes me down a linux bash script which reads from a .xls file and then do some calc.

The task is not as easy as it seems. I guess you should first convert your .xls file to a CSV format (comma separated values) from within Excel (you can export to a .csv file)...

I could do that, but surely not for 0.03 BTC

Xls format is not necessary. I take the table from a web page, so if preferred, I can paste it to a csv file or whatever file format suits the best.

Okay, 0.3 BTC and escrow. The task is not difficult, but you should understand that this is not a monkey business. I have developed sophisticated utilities for importing from and exporting to csv files (c++/qt, for both Windows and Linux), so it is not quite up to my level, and if you find someone cheaper, then more power to you (I'm lazy as hell, lol)...

Just curious, why bash exactly?
legendary
Activity: 1092
Merit: 1001
Anyway, name your price please! I will think of that.
legendary
Activity: 1092
Merit: 1001
Hello there, I am currently looking for someone who writes me down a linux bash script which reads from a .xls file and then do some calc.

The task is not as easy as it seems. I guess you should first convert your .xls file to a CSV format (comma separated values) from within Excel (you can export to a .csv file)...

I could do that, but surely not for 0.03 BTC

Xls format is not necessary. I take the table from a web page, so if preferred, I can paste it to a csv file or whatever file format suits the best.
legendary
Activity: 3514
Merit: 1280
English ⬄ Russian Translation Services
Hello there, I am currently looking for someone who writes me down a linux bash script which reads from a .xls file and then do some calc.

The task is not as easy as it seems. I guess you should first convert your .xls file to a CSV format (comma separated values) from within Excel (you can export to a .csv file)...

I could do that, but surely not for 0.03 BTC
legendary
Activity: 1092
Merit: 1001
Hello there, I am currently looking for someone who writes me down a linux bash script which reads from a .xls file and then do some calc.
I would like to launch the script from the terminal with the command ./script -l path/to/file.xls
This is the algorithm:
Quote
***column A1 to A11 belong to TEAM1
***column A13 to A23 belong to TEAM2[/i]
counterteam1 = 0;
counterteam2 = 0;
sumteam1 = 0;
sumteam2 = 0;

Ask QUESTION1 *** I will personalize it by myself
Will receive input(s) of a number between 1 to 23.
if Input = 0 then terminate the question.
Keep asking for inputs until I give 0.
Inputs are the cell I do not want to be read by the next two for cycles (delete the content of the cell for example).

for (reads cells from A1 to A11) *** REMEMBER TO EXCLUDE THE CELLS GIVEN BY QUESTION1
  if (Ai = Por or Ds or Dc or Dd or MCc or DsCs or DdCd or DdCdDsCs or DsDc or DdDc or DsDdDc)
     then do the calc (sumteam1 = sumteam1 + Di)  and (counter1 = counter1 + 1);
      
for (reads cell from A13 to A23)
  if (Ai = Por or Ds or Dc or Dd or MCc or DsCs or DdCd or DdCdDsCs or DsDc or DdDc or DsDdDc)
     then do the calc (sumteam2 = sumteam2 + Di) and (counter2 = counter2 + 1);

if counterteam1 - counterteam2 is positive, add 5 to sumteam2 for every integer of difference.
if counterteam1 - counterteam2 is negative, add 5 to sumteam1 for every integer of difference.
example: counterteam1 - counterteam2 = 2, => sumteam2 = sumteam2 + (5*2)
                counterteam1 - counterteam2 = -1, => sumteam1 = sumteam 1+ (5*1)
               counterteam1 - counterteam2 = 3, => sumteam2 = sumteam2 + (5*3)


print sumteam1
print sumteam2
print sumteam1 - sumteam2;


Reply with the code and a BTC address please, it should be easy for a programmer to accomplish the task. The very first user who posts a working script will receive a 0.03 BTC as a reward.

Before replying to this thread you can check if by yourself if the script works by running it with the following xls file (paste the following into a blank spreadsheet)
Quote
Por   VIVIANO   SAM   6   -
DsCs   DODO'   Sam   5,5   5,5
Dc   HOEDT   LAZ   5   -
Dc   MANOLAS   Rom   6   6
DdDsCdCs   LETIZIA   CAR   6   -
CcT   NAINGGOLAN   Rom   7   7
MCc   BROZOVICammonizioneassist   Int   6   6,5
CcT   FREULER   Ata   6   6
TA   VAZQUEZammonizionegolfatto   Pal   7,5   10
Pc   ZAZA   Juv   5,5   5,5
Pc   PAVOLETTIgolfatto   Gen   7   10
            
Por   TATARUSANU   FIO   6   -
DsDcCs   PELUSO   Sas   6   6
Dc   BARZAGLI   Juv   6   6
Dc   MUNOZ   Gen   5   5
DdDsCdCs   D'AMBROSIO   Int   5,5   5,5
CcT   VECINO   Fio   7,5   13,5
MCc   ACQUAH   TOR   5   -
MCc   BADELJ   Fio   6,5   6,5
A   TRAJKOVSKI   Pal   5   5
Pc   IMMOBILE   Tor   5,5   5,5
A   THEREAUespulsione   Udi   4,5   3,5

It should give as result

sumteam1 = 39.5
sumteam2 = 40

Cheers!


Jump to: