Commit 27a107f0 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the script debug.py.

parent 1f6837c8
# -*- coding: utf-8 -*-
""" NAME
debug
SYNOPSIS
tool to debug the sources (DataFrame)
DESCRIPTION
Debug sources specific to this application:
- item
- item / year
- item small
- item small / year
- object like
- object like / year
- people / year
- people like
- people like / year
OPTIONS
-h, --help
Display the help and exit.
EXAMPLE
> cd ...tev/lhcbfrance/scripts
> run -S test_lhcbfrance script debug.py -h
> run -S test_lhcbfrance script debug.py --df item
> run -S track_lhcbfrance script debug.py --df item_small_year
AUTHOR
R. Le Gac -- 2016, 2017
"""
import pandas as pd
from plugin_event import (Core,
debug_df,
get_items,
get_items_per_year,
get_items_small,
get_items_small_per_year,
get_objectlike_items,
get_objectlike_items_per_year,
get_people_per_year,
get_peoplelike_items,
get_peoplelike_items_per_year,
Event,
Report,
Timer)
SOURCES = {"items": get_items,
"items_year": get_items_per_year,
"items_small": get_items_small,
"items_small_year": get_items_small_per_year,
"object_like": get_objectlike_items,
"object_like_year": get_objectlike_items_per_year,
"people_like": get_peoplelike_items,
"people_like_year": get_peoplelike_items_per_year,
"people_year": get_people_per_year}
def debug_option(opt):
s = ""
if opt.a:
s += "a"
if opt.c:
s += "c"
if opt.f:
s += "f"
if opt.H:
s += "h"
if opt.i:
s += "i"
if opt.t:
s += "t"
return s
if __name__ == "__main__":
import argparse
import sys
# protection
application = request.application
if application not in ("test_lhcbfrance", "test_teams"):
print "Invalid application", application
sys.exit(1)
# database model
Event.register_sources()
Core.define_tables(db, T)
Report.define_tables(db, T)
# pandas options and matplotlib style
pd.set_option("display.encoding", "utf-8")
pd.set_option("display.width", 150)
# parse options
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
"-a",
action="store_true",
help="activate all debug options")
PARSER.add_argument(
"-e", "--event",
default=1,
help="the event identifier [%(default)s]",
metavar="<int>",
type=int)
PARSER.add_argument(
"-f",
action="store_true",
help="show the whole DataFrame")
PARSER.add_argument(
"-c",
action="store_true",
help="show column")
PARSER.add_argument(
"-H",
action="store_true",
help="show head")
PARSER.add_argument(
"-i",
action="store_true",
help="show index")
PARSER.add_argument(
"-s", "--source",
choices=sorted(SOURCES.keys()),
default="item_small",
help="select the source [%(default)s]")
PARSER.add_argument(
"-t",
action="store_true",
help="show tail")
PARSER.add_argument(
"--yend",
default=request.now.year,
help="upper limit for the year scan [%(default)s]",
metavar="<int>",
type=int)
PARSER.add_argument(
"--ystart",
default=request.now.year,
help="lower limit of the year scan [%(default)s]",
metavar="<int>",
type=int)
OPT = PARSER.parse_args()
# ........................................................................
#
# select project and time period
#
KWARGS = dict(
id_events=OPT.event,
year_start=OPT.ystart,
year_end=OPT.yend)
# ........................................................................
#
# Build and show the source
#
for source, func in SOURCES.iteritems():
if OPT.source == source:
with Timer("build data frame for %s" % source) as t:
df = func(**KWARGS)
debug_df(df, debug_option(OPT))
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment