[web2py] Re: Getting wrong Results with my grading system

2017-11-18 Thread mostwanted
What i want is to reflect an a 'A' if a student gets anything between 100% 
and 80%, hence the line 
if perc>=100:
grade='A'

and get grade 'B' if a student gets anything between79% and 70% hence the 
line
elif perc>=79:
grade='B'
elif perc>=69:
grade='C'
When i coded it i thought it's straight forward it'd reflect correctly but 
instead 70% gives me 'C' and 80% to 90% give me a 'B' I Cant figure out 
what I'm doing wrong where!


On Sunday, November 19, 2017 at 1:06:20 AM UTC+2, Anthony wrote:
>
>
>
> On Saturday, November 18, 2017 at 9:15:36 AM UTC-5, mostwanted wrote:
>>
>> I want grade 'A' to fall within a range of percentages, 'A' ranges from 
>> 80%(being the lowest) to 100%(being the highest), how do i reflect that 
>> here to get the system to grade properly??
>>
>
> if perc >= 80:
>
> The upper range doesn't matter, as presumably 100 is the maximum anyway.
>
> Note, though, that you have defined a B as >= 79. That means that you get 
> a B only if your percentage is between 79 and 80 -- once you hit 80, it's 
> an A. Is that really what you want?
>
> Anthony
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: list:string field length

2017-11-18 Thread Donald McClymont
Issue may be with SQLFORM rather than Pydal - if I have a list string field 
in my case its called answers and put it in a SQLFORM then in form.validate 
if you do

print type(form.vars.answers)

I get str when there is 1 item in my list and list when multiple answers and so 
my validation includes a line like this:


if isinstance(form.vars.answers, list) and len(form.vars.answers) > 1 and 
len(form.vars.answers[1]) > 0:


I just thought I'd mention it as something to be aware of if you start using 
length with list string fields as I always expected it to be a list. 


This is still the case with 2.16.1


Donald



On Friday, November 17, 2017 at 11:47:49 PM UTC, Anthony wrote:

> On Friday, November 17, 2017 at 3:53:02 PM UTC-5, Donald McClymont wrote:
>
>> I don’t think you can set this but not sure why you would want to. 
>>  However beware if testing the length of the field as I think if you only 
>> have 1 item in the list then this is a string and you get the number of 
>> chars in the string.  While if you have more than 1 you get the length of 
>> the list.
>
>
> Can you show some code demonstrating what you mean -- I cannot replicate? 
> If you use the DAL to select data, it automatically converts the native 
> data to a Python list, even if the list includes only a single item. So, if 
> you do something like len(db.mytable(1).my_list_string_field), you should 
> always get the length of the list, not the length of any single element in 
> the list.
>
> Anthony
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Getting wrong Results with my grading system

2017-11-18 Thread Anthony


On Saturday, November 18, 2017 at 9:15:36 AM UTC-5, mostwanted wrote:
>
> I want grade 'A' to fall within a range of percentages, 'A' ranges from 
> 80%(being the lowest) to 100%(being the highest), how do i reflect that 
> here to get the system to grade properly??
>

if perc >= 80:

The upper range doesn't matter, as presumably 100 is the maximum anyway.

Note, though, that you have defined a B as >= 79. That means that you get a 
B only if your percentage is between 79 and 80 -- once you hit 80, it's an 
A. Is that really what you want?

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-18 Thread Leonel Câmara
Do you want to lock between processes or just threads? If it's just between 
threads you can just put the lock in a module instead of a model file. 
Models are executed again on every request so you're creating a new Lock 
each time so threads will be locking different lock instances. Between 
processes you can use Dave's suggestion or you can use portalocker which 
web2py includes.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Getting wrong Results with my grading system

2017-11-18 Thread mostwanted
Thanks for the {{pass}} clarification, its clear now

On Saturday, November 18, 2017 at 2:38:28 PM UTC+2, Anthony wrote:
>
>
> And I'd also be grateful if someone just simple explained what {{pass}} 
>> does in web2py and where do we place it because i find myself placing it in 
>> wrong places and at times it just disrupts the balance of the entire code 
>> if i don't place it correctly, that'd mean a lot, thanks.
>>
>
> The use of {{pass}} is explained here: 
> http://web2py.com/books/default/chapter/29/05/the-views#The-views. Python 
> usually defines code blocks based on indentation, but since the views do 
> not require proper Python indentation, we need an alternate way to define 
> code blocks when the boundaries are not otherwise obvious -- so you use 
> {{pass}} to indicate the end of a code block. For example:
>
> {{if some_condition:}}
> This
> {{else:}}
> That
> {{pass}}
> Now we are outside the "else" block, so this line will always be displayed
> .
>
> Without the {{pass}}, that last line would be part of the "else" block and 
> therefore only display conditionally. Note, we do not need a {{pass}} at 
> the end of the "if" block above, because the {{else:}} implies the end of 
> the "if" block.
>
> Typically, you would need a {{pass}} to indicate the end of an if, else, 
> elif, or for block in a view.
>
> Anthony
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Getting wrong Results with my grading system

2017-11-18 Thread mostwanted
I want grade 'A' to fall within a range of percentages, 'A' ranges from 
80%(being the lowest) to 100%(being the highest), how do i reflect that 
here to get the system to grade properly??


On Saturday, November 18, 2017 at 11:00:45 AM UTC+2, Kiran Subbaraman wrote:
>
> so if `perc >=90%, it is grade `A`? The code should reflect the same then. 
> Right now, it is `A`, if `perc >= 100`, which is not a valid value for 
> `perc`. 
> Am guessing the same is applicable for the `average` check too.
>
> 
> Kiran Subbaramanhttp://subbaraman.wordpress.com/about/
>
> On 18-Nov-17 1:37 PM, mostwanted wrote:
>
>
>  I am getting wrong results with my grading system, i think this is more 
> of a syntax problem, i just don't know where I'm mixing up things. My 
> system is supposed to give students grades depending on what percentages 
> they got but the grades do not correspond well with the percentages. I'm 
> getting wrong grades for percentages, e.g 90% is supposed to give me grade 
> 'A' but it is giving me grade 'B', they are all mixed up!!! Can someone 
> assist please?! Thanks.
>
> Here is my code:
> {{extend 'layout.html'}}
> ..
> ..
> ..
> {{
>  total=0
> for report in form:
> perc=(float(report.marks)/float(report.total))*float(100)
> if perc>=100:
> grade='A'
> elif perc>=79:
> grade='B'
> elif perc>=69:
> grade='C'
> elif perc>=59:
> grade='D'
> elif perc>=39:
> grade='E'
> elif perc>=19:
> grade='U'
> }}
>
> {{pass}}
>   {{
> total+=perc
> average=int(average/totalNum)
> if average>=100:
> avGrade='A'
> elif average>=79:
> avGrade='B'
> elif average>=69:
> avGrade='C'
> elif average>=59:
> avGrade='D'
> elif average>=39:
> avGrade='E'
> elif average>=19:
> avGrade='E'
> }}
> {{pass}}
> 
> {{=report.term.term}}
> {{=report.subject.subject_name}}
> {{=report.marks}}
> {{=report.total}}
>   
> {{=perc}}(%)
> 
> {{=grade}}
> 
> {{=report.comments}}
> 
>
>
>{{pass}}
> {{pass}}
> 
> 
> 
> 
> 
> AVERAGE
> TOTAL/GRADE
> CLASS/PS
> SCHOOL/PS
> 
> 
> {{=average}}(%)
> {{=avGrade}}
> 3
> 21
> 
> 
>
>
> -- 
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> --- 
> You received this message because you are subscribed to the Google Groups 
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to web2py+un...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Getting wrong Results with my grading system

2017-11-18 Thread mostwanted
I want grade 'A' to fall within a range of percentages, 'A' ranges from 
80%(being the lowest) to 100%(being the highest), how do i reflect that 
here to get the system to grade properly??

On Saturday, November 18, 2017 at 11:05:02 AM UTC+2, Jose C wrote:
>
> Simple logic error...
>
> Your first if clause should most likely be:
> if perc >= 90:
>
> in order to trap that value.  
>
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: scheduler can't normal run my script

2017-11-18 Thread Anthony
On Saturday, November 18, 2017 at 1:52:56 AM UTC-5, yytry...@gmail.com 
wrote:
>
> thank for you answer i  use
> python G:\\web2py\\web2py.py -K yj:sss -X -a '1' -i 0.0.0.0 -p 8000 &
> to run my app,can you  give me a example ? i understand the script,but i 
> don't know how to use it in my app
> and when i use scheduler it auto use threading create so many task, i want 
> to control it's quantity,how to do? 
>

Where is your script and how are you running it? If you are starting the 
scheduler worker as above, the scheduler and scheduler task must be defined 
in the context of a web2py app, not a standalone script. From your script 
code, the function defining the task should either go in a model file in 
the app or go in a module and be imported into a model file. The code 
defining the scheduler should go in a model file in the app. And the code 
queuing the task should be executed elsewhere -- you can run the queuing 
code from a web2py shell, define a controller action that queues the task, 
or even directly add a record to the scheduler_task table (possibly via 
appadmin) to queue a task.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: scheduler can't normal run my script

2017-11-18 Thread Anthony

>
> the scheduler_run run_out is 
> ['1']
> 1
> 2
> 5
> CVE-2017-6274
> http://cve.scap.org.cn/CVE-2017-6274.html
> 6
> no except and 6 is print 
> but 
>
>  
> db.get_data.update_or_insert(db.get_data.title==i.get_text(),title=i.get_text(),get_from='cve',
> 
> get_url=i.get('href'),get_time=now,data_condition=condition[0],bug_num=i.get_text())
> is no run,can you tell me why?
>
> In scheduler tasks, you must call db.commit() to commit transactions to 
the database. web2py does this automatically on HTTP requests, but the 
scheduler is not making an HTTP request to web2py.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: JWT questions

2017-11-18 Thread Anthony

>
>
> returned 1, 2, 3, 4,  for the browser, and  1, 1, 1, 1,  for my 
> curl-JWT accesses.  If I wait long enough, the token expires as expected 
> (not very long for the default), but before it expires it acts like the 
> session stays around to keep me "logged in", but also like the session is 
> new every time for the tcount variable.
>

When you make an HTTP request to web2py, it sends back a session cookie. 
Browsers retain and keep sending back the session cookie (throughout the 
course of a browser session), so web2py can continue to identify the 
browser with a particular session. Be default, curl does not retain cookies 
and send them back to the remote server on subsequent requests, so web2py 
has no way of associating each curl request with the same session.

JWT auth does not work via cookies. Rather, the JWT goes in the HTTP 
request headers. So, with curl, you are sending the JWT to web2py on every 
request, and web2py is able to validate the JWT on each request (the JWT 
can be validated based only on its own data -- nothing from a server-side 
session is needed to validate it). web2py, therefore, is not "keeping you 
logged in" -- you are really re-authenticating on every single request by 
sending the JWT in the request headers.

By the way, you can use curl to store and return cookies using the --cookie 
and --cookie-jar options.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Getting wrong Results with my grading system

2017-11-18 Thread Anthony


> And I'd also be grateful if someone just simple explained what {{pass}} 
> does in web2py and where do we place it because i find myself placing it in 
> wrong places and at times it just disrupts the balance of the entire code 
> if i don't place it correctly, that'd mean a lot, thanks.
>

The use of {{pass}} is explained 
here: http://web2py.com/books/default/chapter/29/05/the-views#The-views. 
Python usually defines code blocks based on indentation, but since the 
views do not require proper Python indentation, we need an alternate way to 
define code blocks when the boundaries are not otherwise obvious -- so you 
use {{pass}} to indicate the end of a code block. For example:

{{if some_condition:}}
This
{{else:}}
That
{{pass}}
Now we are outside the "else" block, so this line will always be displayed.

Without the {{pass}}, that last line would be part of the "else" block and 
therefore only display conditionally. Typically, you would need a {{pass}} 
to indicate the end of an if, else, elif, or for block in a view.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Getting wrong Results with my grading system

2017-11-18 Thread Jose C
Simple logic error...

Your first if clause should most likely be:
if perc >= 90:

in order to trap that value.  



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Getting wrong Results with my grading system

2017-11-18 Thread Kiran Subbaraman
so if `perc >=90%, it is grade `A`? The code should reflect the same 
then. Right now, it is `A`, if `perc >= 100`, which is not a valid value 
for `perc`.

Am guessing the same is applicable for the `average` check too.


Kiran Subbaraman
http://subbaraman.wordpress.com/about/

On 18-Nov-17 1:37 PM, mostwanted wrote:


 I am getting wrong results with my grading system, i think this is 
more of a syntax problem, i just don't know where I'm mixing up 
things. My system is supposed to give students grades depending on 
what percentages they got but the grades do not correspond well with 
the percentages. I'm getting wrong grades for percentages, e.g 90% is 
supposed to give me grade 'A' but it is giving me grade 'B', they are 
all mixed up!!! Can someone assist please?! Thanks.


Here is my code:
|
{{extend 'layout.html'}}
..
..
..
{{
         total=0
forreport inform:
        perc=(float(report.marks)/float(report.total))*float(100)
ifperc>=100:
            grade='A'
elifperc>=79:
            grade='B'
elifperc>=69:
            grade='C'
elifperc>=59:
            grade='D'
elifperc>=39:
            grade='E'
elifperc>=19:
            grade='U'
}}

{{pass}}
{{
        total+=perc
        average=int(average/totalNum)
ifaverage>=100:
            avGrade='A'
elif|average|>=79:
            avGrade='B'
elif|average|>=69:
            avGrade='C'
elif|average|>=59:
            avGrade='D'
elif|average|>=39:
            avGrade='E'
elif|average|>=19:
            avGrade='E'
}}
{{pass}}

{{=report.term.term}}
{{=report.subject.subject_name}}
{{=report.marks}}
{{=report.total}}

{{=perc}}(%)

            {{=grade}}

        {{=report.comments}}



       {{pass}}
{{pass}}
    


    
        
            AVERAGE
TOTAL/GRADE
            CLASS/PS
            SCHOOL/PS
        

{{=|average|}}(%)
{{=avGrade}}
3
            21

    
|


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google 
Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to web2py+unsubscr...@googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups "web2py-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Getting wrong Results with my grading system

2017-11-18 Thread mostwanted

 I am getting wrong results with my grading system, i think this is more of 
a syntax problem, i just don't know where I'm mixing up things. My system 
is supposed to give students grades depending on what percentages they got 
but the grades do not correspond well with the percentages. I'm getting 
wrong grades for percentages, e.g 90% is supposed to give me grade 'A' but 
it is giving me grade 'B', they are all mixed up!!! Can someone assist 
please?! Thanks.

Here is my code:
{{extend 'layout.html'}}
..
..
..
{{
 total=0
for report in form:
perc=(float(report.marks)/float(report.total))*float(100)
if perc>=100:
grade='A'
elif perc>=79:
grade='B'
elif perc>=69:
grade='C'
elif perc>=59:
grade='D'
elif perc>=39:
grade='E'
elif perc>=19:
grade='U'
}}

{{pass}}
  {{
total+=perc
average=int(average/totalNum)
if average>=100:
avGrade='A'
elif average>=79:
avGrade='B'
elif average>=69:
avGrade='C'
elif average>=59:
avGrade='D'
elif average>=39:
avGrade='E'
elif average>=19:
avGrade='E'
}}
{{pass}}

{{=report.term.term}}
{{=report.subject.subject_name}}
{{=report.marks}}
{{=report.total}}
  
{{=perc}}(%)

{{=grade}}

{{=report.comments}}



   {{pass}}
{{pass}}





AVERAGE
TOTAL/GRADE
CLASS/PS
SCHOOL/PS


{{=average}}(%)
{{=avGrade}}
3
21




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.