LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2010, 05:20 PM   #1
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Rep: Reputation: 21
python math calculation


def minutes(self):
from decimal import Decimal, ROUND_UP
import os
import math
scale = unicode(self.comboBox7.currentText())
job = os.path.expanduser("~/hpgl-hot-folder/temp.plot")
thestat = os.stat(job)
size = thestat[6]
known = 1000
factor = self.LCDNumber5.value()
if scale==(self.__tr("3.53")):
cut = size / known * 40 / 272
self.LCDNumber17.display(round(cut, 2))
else:
cut = size / known * 6 / 257
self.LCDNumber17.display(round(cut, 2))


In the above all is working great except I'd like to have the "factor" variable adjust the LCDNumber17 display slightly. The slider values range from 1-60 units.I've done some tests and with slider on 30 it takes 40min. with the slider on 5 it takes 46min. I need to find a relationship for the slider valve and as the slider value increases the time (LCDNumber17) goes down correspondingly and put it at the end of the "cut" calculation.

any ideas?

Thanks
 
Old 02-25-2010, 05:23 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Ouch, python post without indentatiton. Any chance you can repost or edit it so that the code is inside "code tags"?

Evo2.
 
Old 02-25-2010, 05:37 PM   #3
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
Sorry about that

I didn't notice till it was to late I hope the code tags I inserted work?


def minutes(self):
from decimal import Decimal, ROUND_UP
import os
import math
scale = unicode(self.comboBox7.currentText())
job = os.path.expanduser("~/hpgl-hot-folder/temp.plot")
thestat = os.stat(job)
size = thestat[6]
known = 1000
factor = self.LCDNumber5.value()
if scale==(self.__tr("3.53")):
cut = size / known * 40 / 272
self.LCDNumber17.display(round(cut, 2))
else:
cut = size / known * 6 / 257
self.LCDNumber17.display(round(cut, 2))
 
Old 02-25-2010, 05:38 PM   #4
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
no it didn't

I inserted a code tag at the start and the end of the code but no change....
 
Old 02-25-2010, 05:39 PM   #5
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
Code:
def minutes(self):
	 from decimal import Decimal, ROUND_UP
	 import os
	 import math
	 scale = unicode(self.comboBox7.currentText())
	 job = os.path.expanduser("~/hpgl-hot-folder/temp.plot")
         thestat = os.stat(job)
         size = thestat[6]
	 known = 1000
	 factor = self.LCDNumber5.value() 
	 if scale==(self.__tr("3.53")):
	     cut = size / known * 40 / 272  
	     self.LCDNumber17.display(round(cut, 2))
	 else:
	     cut = size / known * 6 / 257  
	     self.LCDNumber17.display(round(cut, 2))
 
Old 02-25-2010, 05:50 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by gary_in_springhill View Post
In the above all is working great except I'd like to have the "factor" variable adjust the LCDNumber17 display slightly. The slider values range from 1-60 units.I've done some tests and with slider on 30 it takes 40min. with the slider on 5 it takes 46min. I need to find a relationship for the slider valve and as the slider value increases the time (LCDNumber17) goes down correspondingly and put it at the end of the "cut" calculation.
Sorry I don't understand you code. However, I think I understand that you want to define a function that relates "slider" (what ever that is) to time.

y=m*x + c

m = (46-40)/(5-30) = -6/25 = -0.24
c = 46-m*5 = 47.2

so
y = -0.24*x + 47.2
or
s = -0.24*t + 47.2

or in python
Code:
def t2s( t ):
   return -0.24*t+47.2
Is this what you are looking for?

Evo2.
 
Old 02-25-2010, 06:04 PM   #7
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
yikes! :)

Is there a way to incorporate your calculations into the def I posted as perhaps another variable then applied to the "factor" variable?
 
Old 02-25-2010, 06:20 PM   #8
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
cut = size / known * 40 / 272 * factor (after your calculations on the factor variable) or something like that if it even can be that simple?
 
Old 02-25-2010, 06:34 PM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
The main problem here is that I don't understand your code. You've posted one method from a class with a bunch of member objects and functions which are defined somewhere else. If you can cut your code down to something that can be understood on it's own I might be able to help.

Evo2.
 
Old 02-25-2010, 06:51 PM   #10
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
ok I'll explain better

Sorry I'll explain:

All the calculations that are in the code post work very accurately but the slider value (variable "factor") with units 1-60 influence the time(derived from the "cut" variable) value specified by LCDNumber17 greatly. I did some actual time tests and with a known file size (size variable) with the slider value at 30 it took 40 minutes and the same file at slider value at 5 it took 46 minutes. I was hoping to establish a ratio based on slider units that could be added or multiplied to the
"cut = size / known * 40 / 272" calculation?

File size will vary always
I'm not sure if I'm going the right way to accomplish this or not?
 
Old 02-25-2010, 11:42 PM   #11
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
got around it

Got it done with a bunch of elif statements, not very efficient but it works.

Thanks for your help
gary
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] complex math calculation in shell script needed gary_in_springhill Programming 33 03-20-2010 05:47 AM
graph problems - python is the language but math is the question cs-cam Programming 3 09-03-2005 10:33 PM
improve math calculation... java os2 Programming 1 10-21-2004 06:17 PM
putting a math calculation in a cron job the_rhino Linux - Newbie 3 10-11-2004 01:46 PM
c math calculation alaios Programming 3 06-01-2004 01:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration