def main():
    correct_required = _get_correct_required(sys.argv[1:])
    random.seed(datetime.now())
    total_correct = 0

    while total_correct < correct_required:
        # Choosing a random game
        game = _choose_game()

        # Output the game
        starting_game = lang['starting_game'].format(game.name, total_correct,
                                                     correct_required)
        seperator = '*' * len(starting_game)
        printer.blue(seperator + os.linesep + starting_game + os.linesep +
                     seperator)

        # Get a question and validator function for the game
        question, validator = game.play_game()

        # Ask it
        printer.cyan(question)

        # Loop until an answer is correct
        is_correct = False
        total_incorrect = 0

        while is_correct == False and total_incorrect < retry_limit:
            user_input = _ask_question(lang['submit_answer'])
            is_correct = validator(user_input)

            # If that's not correct, provide a message before looping
            if is_correct == False:
                total_incorrect += 1
                remaining = retry_limit - total_incorrect
                printer.red(lang['incorrect'].format(remaining))

        if is_correct == False:
            print(lang['limit_reached'])
            return  # Must break out, probable infinite loop reached

        printer.green(lang['correct'])
        total_correct += 1
Esempio n. 2
0
def oneFedHcal(d={}, dump=None, crateslots=[],
               nonMatchedQie=[], nonMatchedTp=[],
               printHeaders=None, nTsMax=None, perTs=None):
    h = d["header"]
    t = d["trailer"]
    if 1 <= dump:
        fields = [" FEDid",
                  "  EvN",
                  "       OrN",
                  "    BcN",
                  "minutes",
                  "TTS",
                  "nBytesHW(   SW)",
                  "type",
                  #"CRC16",
                  "nSkip16",
                  "Blk8",
                  ]

        if printHeaders:
            headers = "  ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [" %4d" % h["FEDid"],
                 "0x%07x" % h["EvN"],
                 "0x%08x" % h["OrN"],
                 "%4d" % h["BcN"],
                 "%7.3f" % hw.minutes(h["OrN"], h["BcN"]),
                 (" %1x" % t["TTS"]) if "TTS" in t else "  - ",
                 "    %5d(%5d)" % (t["nWord64"]*8 if "nWord64" in t else "  -1", d["nBytesSW"]),
                 "  %1d " % h["Evt_ty"],
                 #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
                 "%7d" % d["nWord16Skipped"],
                 ]
        if h["uFoV"]:
            sList.append("  %2d" % t["Blk_no8"])

        printer.blue("  ".join(sList))
        if 2 <= dump and dump != 4:
            htrOverview(h)

    if dump <= 2:
        return

    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        if crateslots and (100*block["Crate"] + block["Slot"]) not in crateslots:
            continue
        oneHtr(iBlock=iBlock,
               p=block,
               dump=dump,
               utca=h["utca"],
               nonMatchedQie=nonMatchedQie,
               nonMatchedTp=nonMatchedTp,
               nTsMax=nTsMax,
               perTs=perTs,
        )
Esempio n. 3
0
def oneFedMol(d):
    header = "   ".join([" FEDid  ",
                             "EvN ",
                             "   iBlock",
                             "  nWord64",
                             "magic",
                             ])
    printer.blue("--MOL" + ("-" * len(header)))
    printer.blue(header)

    for iBlock, value in sorted(d.iteritems()):
        printer.blue("   ".join(["  %3d" % value["FEDid"],
                                 "0x%07x" % value["Trigger"],
                                 "%5d" % iBlock,
                                 "    %5d" % value["nWord64"],
                                 "   %4x" % value["magic"],
                             ]))
Esempio n. 4
0
def oneFedMol(d):
    header = "   ".join([" FEDid  ",
                             "EvN ",
                             "   iBlock",
                             "  nWord64",
                             "magic",
                             ])
    printer.blue("--MOL" + ("-" * len(header)))
    printer.blue(header)

    for iBlock, value in sorted(d.iteritems()):
        printer.blue("   ".join(["  %3d" % value["FEDid"],
                                 "0x%07x" % value["Trigger"],
                                 "%5d" % iBlock,
                                 "    %5d" % value["nWord64"],
                                 "   %4x" % value["magic"],
                             ]))
Esempio n. 5
0
def oneFedBu(d):
    header = "   ".join(["magic".rjust(12), "nWord64".rjust(15)])
    printer.blue("--wrapper" + ("-" * len(header)))
    printer.blue(header)
    printer.blue("0x%16x   %7d" % (d["magic"], d["nWord64"]))
Esempio n. 6
0
def oneFedHcal(d={},
               patterns=False,
               dump=None,
               crateslots=[],
               nonMatchedQie=[],
               nonMatchedTp=[],
               printHeaders=None):
    h = d["header"]
    t = d["trailer"]
    if (not patterns) and (1 <= dump):
        fields = [
            " FEDid",
            "  EvN",
            "       OrN",
            "    BcN",
            "minutes",
            " TTS",
            " nBytesHW",
            "nBytesSW",
            #"CRC16",
            "nSkip16",
            "BcN12",
            "EvN8",
            "Blk8",
        ]

        if printHeaders:
            headers = "   ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [
            " %4d" % h["FEDid"],
            "0x%07x" % h["EvN"],
            "0x%08x" % h["OrN"],
            "%4d" % h["BcN"],
            "%7.3f" % utils.minutes(h["OrN"], h["BcN"]),
            ("  %1x" % t["TTS"]) if "TTS" in t else "  - ",
            ("   %5d" % (t["nWord64"] * 8)) if "nWord64" in t else "    --  ",
            "   %5d" % d["nBytesSW"],
            #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
            "%7d" % d["nWord16Skipped"],
        ]
        if h["uFoV"]:
            sList += [
                "   %4d" % t["BcN12"],
                "0x%02x" % t["EvN8"],
                "  %2d" % t["Blk_no8"],
            ]

        printer.blue("   ".join(sList))
        if 2 <= dump:
            htrOverview(h)

    printColumnHeaders = True
    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        if "patternData" in block:
            oneHtrPatterns(p=block, patterns=patterns, header=h, iBlock=iBlock)
        elif 3 <= dump:
            printColumnHeaders = oneHtr(
                p=block,
                printColumnHeaders=printColumnHeaders,
                dump=dump,
                crateslots=crateslots,
                utca=h["utca"],
                nonMatchedQie=nonMatchedQie,
                nonMatchedTp=nonMatchedTp,
            )
Esempio n. 7
0
def oneFedBu(d):
    header = "   ".join(["magic".rjust(12), "nWord64".rjust(15)])
    printer.blue("--wrapper" + ("-" * len(header)))
    printer.blue(header)
    printer.blue("0x%16x   %7d" % (d["magic"], d["nWord64"]))
Esempio n. 8
0
def oneFedHcal(d={}, patterns=False, dump=None, crateslots=[],
               nonMatchedQie=[], nonMatchedTp=[],
               printHeaders=None):
    h = d["header"]
    t = d["trailer"]
    if (not patterns) and (1 <= dump):
        fields = [" FEDid",
                  "  EvN",
                  "       OrN",
                  "    BcN",
                  "minutes",
                  " TTS",
                  " nBytesHW",
                  "nBytesSW",
                  #"CRC16",
                  "nSkip16",
                  "BcN12",
                  "EvN8",
                  "Blk8",
                  ]

        if printHeaders:
            headers = "   ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [" %4d" % h["FEDid"],
                 "0x%07x" % h["EvN"],
                 "0x%08x" % h["OrN"],
                 "%4d" % h["BcN"],
                 "%7.3f" % utils.minutes(h["OrN"], h["BcN"]),
                 ("  %1x" % t["TTS"]) if "TTS" in t else "  - ",
                 ("   %5d" % (t["nWord64"]*8)) if "nWord64" in t else "    --  ",
                 "   %5d" % d["nBytesSW"],
                 #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
                 "%7d" % d["nWord16Skipped"],
                 ]
        if h["uFoV"]:
            sList += ["   %4d" % t["BcN12"],
                      "0x%02x" % t["EvN8"],
                      "  %2d" % t["Blk_no8"],
                      ]

        printer.blue("   ".join(sList))
        if 2 <= dump:
            htrOverview(h)

    printColumnHeaders = True
    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        if "patternData" in block:
            oneHtrPatterns(p=block,
                           patterns=patterns,
                           header=h,
                           iBlock=iBlock)
        elif 3 <= dump:
            printColumnHeaders = oneHtr(p=block,
                                        printColumnHeaders=printColumnHeaders,
                                        dump=dump,
                                        crateslots=crateslots,
                                        utca=h["utca"],
                                        nonMatchedQie=nonMatchedQie,
                                        nonMatchedTp=nonMatchedTp,
                                        )
Esempio n. 9
0
def oneFedHcal(d={}, dump=None, crateslots=[],
               nonMatchedQie=[], nonMatchedTp=[],
               printHeaders=None):
    h = d["header"]
    t = d["trailer"]
    if 1 <= dump:
        fields = [" FEDid",
                  "  EvN",
                  "       OrN",
                  "    BcN",
                  "minutes",
                  " TTS",
                  "nBytesHW(   SW)",
                  "type",
                  #"CRC16",
                  "nSkip16",
                  "BcN12",
                  "EvN8",
                  "Blk8",
                  ]

        if printHeaders:
            headers = "  ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        sList = [" %4d" % h["FEDid"],
                 "0x%07x" % h["EvN"],
                 "0x%08x" % h["OrN"],
                 "%4d" % h["BcN"],
                 "%7.3f" % utils.minutes(h["OrN"], h["BcN"]),
                 ("  %1x" % t["TTS"]) if "TTS" in t else "  - ",
                 "    %5d(%5d)" % (t["nWord64"]*8 if "nWord64" in t else "  -1", d["nBytesSW"]),
                 "  %1d " % h["Evt_ty"],
                 #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
                 "%7d" % d["nWord16Skipped"],
                 ]
        if h["uFoV"]:
            sList += [" %4d" % t["BcN12"],
                      "0x%02x" % t["EvN8"],
                      "  %2d" % t["Blk_no8"],
                      ]

        printer.blue("  ".join(sList))
        if 2 <= dump:
            htrOverview(h)

    if dump <= 2:
        return

    printColumnHeaders = True
    for iBlock, block in sorted(d["htrBlocks"].iteritems()):
        printColumnHeaders = oneHtr(iBlock=iBlock,
                                    p=block,
                                    printColumnHeaders=printColumnHeaders,
                                    dump=dump,
                                    crateslots=crateslots,
                                    utca=h["utca"],
                                    nonMatchedQie=nonMatchedQie,
                                    nonMatchedTp=nonMatchedTp,
                                   )
Esempio n. 10
0
def oneFedHcal(d={}, dump=None, crateslots=[],
               nonMatchedQie=[], nonMatchedTp=[],
               printHeaders=None, nTsMax=None, perTs=None):
    h = d["header"]
    t = d["trailer"]
    if 1 <= dump:
        if "htrBlocks" in d:
            fields = [" FEDid",
                      "  EvN",
                      "       OrN",
                      "    BcN",
                      "minutes",
                      "TTS",
                      "nBytesHW(nBytesSW)",
                      "type",
                      #"CRC16",
                      "nSkip16",
                      "Blk8",
                     ]
        elif "histograms" in d:
            fields = [" FEDid",
                      "  EvN",
                      "     nOrbits",
                      " minutes",
                      "TTS",
                      "nBytesHW(nBytesSW)",
                      "   L1A  ",
                      "ver",
                      "perCap",
                      "nBins",
                      "nHist",
                     ]
        else:
            fields = [" FEDid",
                      "  EvN",
                      "   nBytesHW(nBytesSW)",
                      "type",
                     ]

        if printHeaders:
            headers = "  ".join(fields)
            printer.blue("-" * len(headers))
            printer.blue(headers)

        if "htrBlocks" in d:
            sList = [" %4d" % h["FEDid"],
                     "0x%07x" % h["EvN"],
                     "0x%08x" % h["OrN"],
                     "%4d" % h["BcN"],
                     "%7.3f" % hw.minutes(h["OrN"], h["BcN"]),
                     (" %1x" % t["TTS"]) if "TTS" in t else "  - ",
                     " %8d(%8d)" % (t["nWord64"]*8 if "nWord64" in t else -1, d["nBytesSW"]),
                     "  %1d " % h["Evt_ty"],
                     #(" 0x%04x" % t["CRC16"]) if "CRC16" in t else "   - ",
                     "%7d" % d["nWord16Skipped"],
                    ]
            if h["uFoV"]:
                sList.append("  %2d" % t["Blk_no8"])

        elif "histograms" in d:
            sList = [" %4d" % h["FEDid"],
                     "0x%07x" % h["EvN"],
                     "0x%08x" % (h["OrN1"] - h["OrN0"]),
                     "%7.3f" % hw.minutes(h["OrN0"], 0),
                     (" %1x" % t["TTS"]) if "TTS" in t else "  - ",
                     " %8d(%8d)" % (t["nWord64"]*8 if "nWord64" in t else -1, d["nBytesSW"]),
                     "0x%07x" % h["L1A"],
                     "%1d" % h["version"],
                     "   %1d" % h["perCap"],
                     "   %3d" % h["nBins"],
                     "   %3d" % h["nHist"],
                    ]
        else:
            sList = [" %4d" % h["FEDid"],
                     "0x%07x" % h["EvN"],
                     "%8d(%8d)" % (t["nWord64"]*8 if "nWord64" in t else -1, d["nBytesSW"]),
                     "  %1d " % h["Evt_ty"],
                     # "%7d" % d["nWord16Skipped"],
                    ]

        printer.blue("  ".join(sList))
        if 2 <= dump and dump != 4 and "htrBlocks" in d:
            htrOverview(h)

    if dump <= 2:
        return

    if "htrBlocks" in d:
        for iBlock, block in sorted(d["htrBlocks"].items()):
            if crateslots and (100*block["Crate"] + block["Slot"]) not in crateslots:
                continue
            oneHtr(iBlock=iBlock,
                   p=block,
                   dump=dump,
                   utca=h["utca"],
                   nonMatchedQie=nonMatchedQie,
                   nonMatchedTp=nonMatchedTp,
                   nTsMax=nTsMax,
                   perTs=perTs,
                  )
    elif "histograms" in d:
        for iBlock, block in sorted(d["histograms"].items()):
            if crateslots and (100*block["Crate"] + block["Slot"]) not in crateslots:
                continue
            oneHistogram(iBlock, block, dump)