[Tutor] Basic Question about Visualization for enduser

2019-06-25 Thread Sinardy Xing
Hi,

I am a newbie with python and the data visualization.
I have completed pandas.DataFrame stuff and also the matplotlib.

All of the example that I learned from internet currently are using the
Anaconda Jupyter Notebook.
I know there are API where we can output the result of the graph to png,
will that be possible all these done automatically and dynamically via an
apps ?

Thanks

Kind regards
Sinardy
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Basic Question about Visualization for enduser

2019-06-25 Thread Sinardy Xing
Hi Mats,

Thanks for the reply. I am so sorry the question was not clear. I was
rushing home when composing the question.

I have learned python and a little about the pandas lib also the
visualization lib such as maplotlib, I also learn on how to generate the
output (thanks again for that example I learned that too few days ago).

My question is, how currently all of this great technology glue together
and as a final product for the enduser. Because I cant imagine that we
install Anaconda Jupyter Notebook at frontend for the enduser to use it,
and give end user bunch of *.py

I read a little bit about Django web framework, I am not sure if my
understanding is correct. Therefore we are using Django as frontend tier
then it connected to backend python server running the calculation and all
other python stuff including the charting and send back the result to
django front end server for end user to consume.


My question is how is the end to end commonly use by company product, how
they present those charts to end user.?

Thanks very much for your kind reply, I am very new in this and all the
information is via selfstudy and online document including this forum.


Regards,
Sinardy









On Tue, Jun 25, 2019 at 10:27 PM Mats Wichmann  wrote:

> On 6/25/19 6:39 AM, Sinardy Xing wrote:
> > Hi,
> >
> > I am a newbie with python and the data visualization.
> > I have completed pandas.DataFrame stuff and also the matplotlib.
> >
> > All of the example that I learned from internet currently are using the
> > Anaconda Jupyter Notebook.
> > I know there are API where we can output the result of the graph to png,
> > will that be possible all these done automatically and dynamically via an
> > apps ?
>
> You can generate graphs with mathplotlib.  If you're specifically
> looking for a png, it looks a bit like this (assuming you want to follow
> the usual conventions for shortening the name, which certainly isn't
> required):
>
> from matplotlib import pyplot as plt
>
> plt.savefig('foo.png')
>
> savefig looks at the file extension in determining what to output.
>
> Without a specific question, I'm not sure what else we can say...
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Create Logging module

2019-08-01 Thread Sinardy Xing
Hi,

I am learning to create python logging.

My goal is to create a logging module where I can use as decorator in my
main app

following is the logging code

 start here---

import logging

#DEBUG: Detailed information, typically of interest only when
diagnosing problems.
#INFO : Confirmation that things are working as expected.
#WARNING  (default): An indication that something unexpected happened, or
indicative of some problem in the near future
# (e.g. 'disk space low'). The software is still working as
expected.
#ERROR: Due to a more serious problem, the software has not been able
to perform some function.
#CRITICAL :A serious error, indicating that the program itself may be
unable to continue running.

from functools import wraps

def logme(func_to_log):
import logging

#Without getLogger name it will log all in root
logger = logging.getLogger(__name__)

#Check log level within understanable parameter, set to INFO if is not
 permitable value
def check_log_level(logleveltocheck):
if any(logleveltocheck.upper() in lf for lf in ['DEBUG',
'INFO', 'WARNING', 'ERROR', 'CRITICAL']):
return logleveltocheck.upper()
else:
return 'INFO'

log_file_level='INFO' #check_log_level('info')
log_console_level='INFO' #check_log_level('info')

#root level
logger.setLevel('INFO')

formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s
:: %(message)s')

#Read log file from parameter
logfile='mylogfile.log'
file_handler = logging.FileHandler(logfile)
file_handler.setLevel(log_file_level)
file_handler.setFormatter(formatter)

stream_handler = logging.StreamHandler()
stream_handler.setLevel(log_console_level)
stream_handler.setFormatter(formatter)

logger.addHandler()
logger.addHandler(stream_handler)

#this wraps is to make sure we are returning func_to_log instead of
wrapper
@wraps(func_to_log)
def wrapper(*args, **kwargs):
logger.info('Ran with args: {}, and kwargs: {}'.format(args,
kwargs))
return func_to_log(*args, **kwargs)

return wrapper


def timer(func_to_log):
import time

#this wraps is to make sure we are returning func_to_log instead of
wrapper
@wraps(func_to_log)
def wrapper(*args, **kwargs):
t1 = time.time()
result = func_to_log(*args, **kwargs)
t2 = time.time() - t1
print('{} ran in {} sec'.format(func_to_log.__name__, t2))
return result

--- end here---


following is my main app

-- start here--
from loggingme import logme

def say_hello(name, age):
print('Hello {}, I am {}'.format(name, age))

#say_hello=logme(say_hello('Sinardy'))
@logme
say_hello('Tonny', 8)

--- end here---


I have error look like in the wrapper.

Can someone point to me where is the issue or is this the correct way to
create logging module?

PS: above code with python 3.7.4

Thank you.

regards,
C
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Create Logging module

2019-08-01 Thread Sinardy Xing
Hi Steven,

Thanks for your reply, I was copy and paste the code in the email as a text.
I dont know why it becoming photo or screen shot when you view it ?

When I run the module individually it is no error only when I use as
decorator I have error.



$ cat mainapp.py

from loggingme import logme


def say_hello(name, age):

print('Hello {}, I am {}'.format(name, age))


@logme

say_hello('Tonny', 8)



$ python3 mainapp.py

  File "mainapp.py", line 8

say_hello('Tonny', 8)

^

SyntaxError: invalid syntax

On Thu, Aug 1, 2019 at 8:42 PM Steven D'Aprano  wrote:

> On Thu, Aug 01, 2019 at 05:11:04PM +0800, Sinardy Xing wrote:
>
> > I have error look like in the wrapper.
> >
> > Can someone point to me where is the issue
>
> No, but you can.
>
> When the error occurs, Python will print a traceback containing a list
> of the lines of code being executed, and the final error. You should
> read that error, especially the last line, and it will tell you the line
> of code that failed and give you a clue why it failed.
>
> We can help you if you copy and paste the full traceback, starting with
> the line "Traceback..." to the end.
>
> Don't take a screen shot or photo and send that, instead copy and paste
> the text into your email.
>
> (P.S. please reply to the mailing list, not to me personally.)
>
>
> --
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Create Logging module

2019-08-01 Thread Sinardy Xing
Hi I solve my problem,

the decorator need to be above the function not when executed. :)

Thanks for reading.

:)



On Thu, Aug 1, 2019 at 8:42 PM Steven D'Aprano  wrote:

> On Thu, Aug 01, 2019 at 05:11:04PM +0800, Sinardy Xing wrote:
>
> > I have error look like in the wrapper.
> >
> > Can someone point to me where is the issue
>
> No, but you can.
>
> When the error occurs, Python will print a traceback containing a list
> of the lines of code being executed, and the final error. You should
> read that error, especially the last line, and it will tell you the line
> of code that failed and give you a clue why it failed.
>
> We can help you if you copy and paste the full traceback, starting with
> the line "Traceback..." to the end.
>
> Don't take a screen shot or photo and send that, instead copy and paste
> the text into your email.
>
> (P.S. please reply to the mailing list, not to me personally.)
>
>
> --
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Create Logging module

2019-08-02 Thread Sinardy Xing
Thanks Alan,

I learn alot.

logger.setLevel('INFO')   <- If I did not include this in the code it
not generating any log I am confuse because I have setLevel to file_handler
and to stream_handler
file_handler.setLevel('DEBUG')
stream_handler.setLevel('DEBUG')


On Fri, Aug 2, 2019 at 12:14 AM Alan Gauld via Tutor 
wrote:

> On 01/08/2019 10:11, Sinardy Xing wrote:
>
> >  start here---
> >
> > import logging
> >
> >  ..snip...
>
>
> > from functools import wraps
> >
> > def logme(func_to_log):
> > import logging
>
> You don't need the import, it's already done in the first line.
>
>
> > #Check log level within understanable parameter, set to INFO if is
> not
> >  permitable value
> > def check_log_level(logleveltocheck):
>
> This looks like an indentation error?
> It should be at the same level as the import statement.
>
> > if any(logleveltocheck.upper() in lf for lf in ['DEBUG',
> > 'INFO', 'WARNING', 'ERROR', 'CRITICAL']):
> > return logleveltocheck.upper()
>
> Are you sure that is what you want? It seems very complicated unless you
> are allowing the user to supply an abbreviated form. Otherwise
>
> if logleveltocheck.upper() in ['DEBUG', 'INFO', 'WARNING',
>'ERROR', 'CRITICAL']:
> return logleveltocheck.upper()
>
> might be easier?
>
> > else
> > return 'INFO'
> >
> > log_file_level='INFO' #check_log_level('info')
> > log_console_level='INFO' #check_log_level('info')
> >
> > #root level
> > logger.setLevel('INFO')
>
> I'm not sure what this is supposed to be doing!
>
> > formatter = logging.Formatter('%(asctime)s :: %(name)s ::
> %(levelname)s
> > :: %(message)s')
> >
> > #Read log file from parameter
> > logfile='mylogfile.log'
> > file_handler = logging.FileHandler(logfile)
> > file_handler.setLevel(log_file_level)
> > file_handler.setFormatter(formatter)
> >
> > stream_handler = logging.StreamHandler()
> > stream_handler.setLevel(log_console_level)
> > stream_handler.setFormatter(formatter)
> >
> > logger.addHandler()
> > logger.addHandler(stream_handler)
> >
> > #this wraps is to make sure we are returning func_to_log instead of
> > wrapper
> > @wraps(func_to_log)
> > def wrapper(*args, **kwargs):
> > logger.info('Ran with args: {}, and kwargs: {}'.format(args,
> > kwargs))
> > return func_to_log(*args, **kwargs)
> >
> > return wrapper
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Create Logging module

2019-08-02 Thread Sinardy Xing
Thank you Alan,

- from previous mail 

> if any(logleveltocheck.upper() in lf for lf in ['DEBUG',
> 'INFO', 'WARNING', 'ERROR', 'CRITICAL']):
> return logleveltocheck.upper()

Are you sure that is what you want? It seems very complicated unless you
are allowing the user to supply an abbreviated form. Otherwise

if logleveltocheck.upper() in ['DEBUG', 'INFO', 'WARNING',
   'ERROR', 'CRITICAL']:
return logleveltocheck.upper()

might be easier?

> else
> return 'INFO'
>
> log_file_level='INFO' #check_log_level('info')
> log_console_level='INFO' #check_log_level('info')
>
> #root level
> logger.setLevel('INFO')

I'm not sure what this is supposed to be doing!

-- end 

I am thinking about a module where user can change the logging mode and
doing so without modifying code, I am thinking to extend it with parameter
module.
I seen many software that if user set logging Level 1,2,3,4 or support
mode, then application will create more information in the log file
accordingly. The method I am using most likely is wrong. I dont know where
should I trigger the log Level to achieve parameterize logging mode.


I have one question I have following set

stream_handler.setLevel('INFO')<--- handler to console
file_handler.setLevel('INFO')  < handler to file

both are added to logger

  logger.addHandler(file_handler)
  logger.addHandler(stream_handler)

If I did not set the logger.setLevel like following

logger.setLevel('INFO')

the logger unable to process

logger.info('Current log level is : {}'.format(logger.level))
 > return 10 if  logger.setLevel('DEBUG') if not



My question is what is the different between

stream_handler.setLevel('INFO')

and

logger.setLevel('INFO')

Why do we need
 logger.setLevel('INFO')

if we stated following

stream_handler.setLevel('INFO')<--- handler to console
file_handler.setLevel('INFO')  < handler to file





--- complete code

import logging

#DEBUG: Detailed information, typically of interest only when
diagnosing problems.
#INFO : Confirmation that things are working as expected.
#WARNING  (default): An indication that something unexpected happened, or
indicative of some problem in the near future
# (e.g. 'disk space low'). The software is still working as
expected.
#ERROR: Due to a more serious problem, the software has not been able
to perform some function.
#CRITICAL :A serious error, indicating that the program itself may be
unable to continue running.

from functools import wraps

def logme(orig_func):
#Without getLogger name it will log all in root
logger = logging.getLogger(__name__)

#Check log level within understanable parameter, set to INFO if is not
 permitable value
def check_log_level(logleveltocheck):
#as per advised from Alan Gauld @python.org
if logleveltocheck.upper() in ['DEBUG', 'INFO', 'WARNING', 'ERROR',
'CRITICAL']:
return logleveltocheck.upper()
else:
return 'INFO'

log_file_level='INFO' #check_log_level('info')
log_console_level='INFO' #check_log_level('info')

#root level
logger.setLevel('DEBUG')

formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s
:: %(message)s')

#Read log file from parameter
logfile='mylogfile.log'
file_handler = logging.FileHandler(logfile)
file_handler.setLevel(log_file_level)
file_handler.setFormatter(formatter)

stream_handler = logging.StreamHandler()
stream_handler.setLevel(log_console_level)
stream_handler.setFormatter(formatter)

logger.addHandler(file_handler)
logger.addHandler(stream_handler)

#this wraps is to make sure we are returning orig_func instead of
wrapper
@wraps(orig_func)
def wrapper(*args, **kwargs):
logger.info('Ran with args: {}, and kwargs: {}'.format(args,
kwargs))
logger.info('Current log level is : {}'.format(logger.level))
return orig_func(*args, **kwargs)
return wrapper

def timer(orig_func):
import time

#this wraps is to make sure we are returning orig_func instead of
wrapper
@wraps(orig_func)
def wrapper(*args, **kwargs):
t1 = time.time()
result = orig_func(*args, **kwargs)
t2 = time.time() - t1
print('{} ran in {} sec'.format(orig_func.__name__, t2))
return result

@logme