parent
8d33c8b0e2
commit
33dc4ff2e3
|
@ -131,37 +131,37 @@ sub get_reporting_aliases {
|
|||
my $self = shift;
|
||||
|
||||
my $rdmr = TBB::DataManager::Relational->new(
|
||||
host => "reports.v2.tbb",
|
||||
port => 5432,
|
||||
db => "reporting",
|
||||
user => "tbbv2db",
|
||||
host => "reports.v2.tbb",
|
||||
port => 5432,
|
||||
db => "reporting",
|
||||
user => "tbbv2db",
|
||||
password => "reports",
|
||||
);
|
||||
|
||||
my $aliases_aref = $rdmr->select(select => "alias, question, type",
|
||||
from => "user_data_alias");
|
||||
from => "user_data_alias");
|
||||
|
||||
$self->{aliases} = [];
|
||||
|
||||
# make sure each alias is valid; undefined formulas or conditions will give
|
||||
# us problems down the road
|
||||
foreach my $alias (@$aliases_aref) {
|
||||
eval {
|
||||
my $id = TBB::ID::normalize($alias->{question});
|
||||
$alias->{question} = $id;
|
||||
if(TBB::ID::is_a($id, "question")) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} elsif($TBB::BenefitDelivery::ResourceManager->get_component($id)) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} else {
|
||||
write_log("error", "Alias \"$alias->{question}\" does not exist");
|
||||
eval {
|
||||
my $id = TBB::ID::normalize($alias->{question});
|
||||
$alias->{question} = $id;
|
||||
if(TBB::ID::is_a($id, "question")) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} elsif($TBB::BenefitDelivery::ResourceManager->get_component($id)) {
|
||||
push(@{$self->{aliases}}, $alias);
|
||||
} else {
|
||||
write_log("error", "Alias \"$alias->{question}\" does not exist");
|
||||
}
|
||||
};
|
||||
if($@) {
|
||||
write_log("error", "There was a problem with \"$alias->{question}\": $@");
|
||||
}
|
||||
};
|
||||
if($@) {
|
||||
write_log("error", "There was a problem with \"$alias->{question}\": $@");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# this will help to make sure that the exports for each user are proceeding
|
||||
# correctly
|
||||
write_log("notice", "We are reporting on " . scalar(@{$self->{aliases}}) . " aliases.");
|
||||
|
@ -173,11 +173,11 @@ sub get_reporting_aliases {
|
|||
# cleaner
|
||||
sub data_by_user_sql {
|
||||
my $self = shift;
|
||||
|
||||
|
||||
my $sql = "CREATE TABLE data_by_user (id_user integer PRIMARY KEY, ";
|
||||
$sql .= join(", ", map { "$_->{alias} $_->{type}" } @{$self->{aliases}});
|
||||
$sql .= ");";
|
||||
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
@ -194,14 +194,14 @@ sub populate {
|
|||
'',
|
||||
{RaiseError => 1});
|
||||
eval { $rdbh->do("DROP TABLE data_by_user;"); };
|
||||
|
||||
|
||||
# build new data_by_user table
|
||||
my $sql = $self->data_by_user_sql();
|
||||
print STDERR "FFF: $sql\n";
|
||||
$rdbh->do($sql);
|
||||
print STDERR "GGG: we are ok\n";
|
||||
#exit(1);
|
||||
|
||||
|
||||
my @report_fields = map {$_->{alias}} @{$self->{aliases}};
|
||||
push(@report_fields, "id_user");
|
||||
@report_fields = sort(@report_fields);
|
||||
|
@ -210,7 +210,7 @@ sub populate {
|
|||
#print STDERR "JJJ: $sql\n";
|
||||
my $sth = $rdbh->prepare($sql);
|
||||
#exit(1);
|
||||
|
||||
|
||||
# for each client user, grab their system_data_id (which is
|
||||
# a session ID); we get an array of session_id references.
|
||||
my $fields = "id_user, system_data_id";
|
||||
|
@ -219,17 +219,17 @@ sub populate {
|
|||
my $session_ids = $self->{dmr}->select(select => $fields,
|
||||
from => $table,
|
||||
where => $where);
|
||||
|
||||
|
||||
# for each hash in the array we made (each session ID)
|
||||
my $processed = 0;
|
||||
my $total = scalar(@$session_ids);
|
||||
foreach my $session_id (@$session_ids) {
|
||||
$processed++;
|
||||
|
||||
|
||||
my $system_id = $session_id->{system_data_id};
|
||||
my $client_id = $session_id->{id_user};
|
||||
write_log('info', "Exporting $system_id (user: $client_id) ($processed/$total)");
|
||||
|
||||
|
||||
# we need to see if there is a session ID or not in the
|
||||
# sessions table. there almost certainly won't be more
|
||||
# than one but we test anyway. unless there is exactly
|
||||
|
@ -246,33 +246,33 @@ sub populate {
|
|||
write_log('warn', "Session $system_id is not unique ($count found)");
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
my $csd = TBB::ClientSystemData->new($system_id, "reporter");
|
||||
my $dms = $csd->retrieve_data_manager_session();
|
||||
|
||||
my $dms = $csd->retrieve_data_manager_session();
|
||||
|
||||
my $user_data = TBB::UserData::New->new(data_manager_relational => $self->{dmr},
|
||||
data_manager_session => $dms,
|
||||
client_system_data => $csd,
|
||||
current_client_id => $client_id);
|
||||
|
||||
data_manager_session => $dms,
|
||||
client_system_data => $csd,
|
||||
current_client_id => $client_id);
|
||||
|
||||
my $user_data_obj = {'id_user' => $client_id};
|
||||
foreach my $alias_href (@{$self->{aliases}}) {
|
||||
my $alias = $alias_href->{alias};
|
||||
my $id = $alias_href->{question};
|
||||
my $type = $alias_href->{type};
|
||||
|
||||
my $value = $user_data->retrieve_value(base => $id,
|
||||
this_id_user => $client_id);
|
||||
$value ||= "";
|
||||
|
||||
$user_data_obj->{$alias} = $value;
|
||||
foreach my $alias_href (@{$self->{aliases}}) {
|
||||
my $alias = $alias_href->{alias};
|
||||
my $id = $alias_href->{question};
|
||||
my $type = $alias_href->{type};
|
||||
|
||||
my $value = $user_data->retrieve_value(base => $id,
|
||||
this_id_user => $client_id);
|
||||
$value ||= "";
|
||||
|
||||
$user_data_obj->{$alias} = $value;
|
||||
}
|
||||
|
||||
my @values = ();
|
||||
foreach my $name (@report_fields) {
|
||||
push(@values, $user_data_obj->{$name});
|
||||
}
|
||||
$sth->execute(@values);
|
||||
|
||||
my @values = ();
|
||||
foreach my $name (@report_fields) {
|
||||
push(@values, $user_data_obj->{$name});
|
||||
}
|
||||
$sth->execute(@values);
|
||||
|
||||
write_log('debug', " Saving " . scalar(keys(%$user_data_obj)) . " components") if TBB::LogManager::writes_at('debug');
|
||||
#write_log('debug', " User Data Obj: " . Dumper($user_data_obj)) if TBB::LogManager::writes_at('debug');
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
import sys
|
||||
|
||||
color_list = []
|
||||
color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
|
||||
color_list.extend(['\033[3%d;1m' % x for x in range(0, 8)])
|
||||
color_list.append('\033[0m')
|
||||
|
||||
color_names = [
|
||||
'black', 'dred', 'dgreen', 'brown', 'dblue', 'dpurple', 'dcyan', 'lgrey',
|
||||
'dgrey', 'lred', 'lgreen', 'yellow', 'lblue', 'lpurple', 'lcyan', 'white',
|
||||
'unset',
|
||||
]
|
||||
|
||||
color_dict ={}
|
||||
for i in range(0, len(color_list)):
|
||||
color_dict[color_names[i]] = color_list[i]
|
||||
|
||||
class Highlighter:
|
||||
def __init__(self, lexer):
|
||||
self.lexer = lexer
|
||||
self.tokens = []
|
||||
|
||||
def display(self):
|
||||
def display(self, token_colors={}, debug=False):
|
||||
for group in self.tokens:
|
||||
for token in group:
|
||||
if token.name in token_colors:
|
||||
color_name = token_colors[token.name]
|
||||
sys.stdout.write(color_dict[color_name])
|
||||
elif debug:
|
||||
raise Exception, "no highlighting for %r" % token.name
|
||||
sys.stdout.write(token.string)
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.write('\n')
|
||||
|
||||
def highlight(self, lines):
|
||||
self.tokens = [[] for l in lines]
|
||||
|
|
4
lex2.py
4
lex2.py
|
@ -221,6 +221,10 @@ class DualRegionRule(Rule):
|
|||
|
||||
class Grammar:
|
||||
rules = []
|
||||
def __init__(self):
|
||||
for rule in self.rules:
|
||||
if hasattr(rule, 'grammar') and rule.grammar is None:
|
||||
rule.grammar = self
|
||||
|
||||
class Lexer:
|
||||
def __init__(self, name, grammar):
|
||||
|
|
32
lex2_perl.py
32
lex2_perl.py
|
@ -115,11 +115,11 @@ class PerlGrammar(Grammar):
|
|||
pattern=r"(?<!->)(?:STDIN|STDERR|STDOUT|and|cmp|continue|do|else|elsif|eq|eval|foreach|for|if|last|my|next|ne|not|or|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])",
|
||||
),
|
||||
PatternRule(
|
||||
name=r'hash_bareword_index',
|
||||
name=r'bareword_hash_index',
|
||||
pattern=r'(?<={) *[A-Za-z0-9_]+(?=})',
|
||||
),
|
||||
PatternRule(
|
||||
name=r'literal_hash_bareword_index',
|
||||
name=r'bareword_hash_key',
|
||||
pattern=r'[A-Za-z0-9_]+(?= *=>)',
|
||||
),
|
||||
PatternRule(
|
||||
|
@ -226,7 +226,7 @@ class PerlGrammar(Grammar):
|
|||
),
|
||||
PatternRule(
|
||||
name=r'sub',
|
||||
pattern=r"(?<=sub )[a-zA-Z_][a-zA-Z_0-9]*(?=[ \n]*{)",
|
||||
pattern=r"(?<=sub )[a-zA-Z_][a-zA-Z_0-9]*(?= *{)",
|
||||
),
|
||||
PatternRule(
|
||||
name=r'use',
|
||||
|
@ -258,11 +258,33 @@ class PerlGrammar(Grammar):
|
|||
),
|
||||
PatternRule(
|
||||
name=r'bareword_method',
|
||||
pattern=r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]* *\(",
|
||||
pattern=r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()",
|
||||
),
|
||||
#PatternRule(
|
||||
# name=r'delimiter',
|
||||
# pattern=r"\(|\)|\[|\]|{|}|,|;|->|=>|=|\?|(?<!:):(?!=:)",
|
||||
#),
|
||||
RegionRule(
|
||||
name=r'paren',
|
||||
start=r'\(',
|
||||
grammar=None,
|
||||
end=r'\)',
|
||||
),
|
||||
RegionRule(
|
||||
name=r'brace',
|
||||
start=r'{',
|
||||
grammar=None,
|
||||
end=r'}',
|
||||
),
|
||||
RegionRule(
|
||||
name=r'bracket',
|
||||
start=r'\[',
|
||||
grammar=None,
|
||||
end=r'\]',
|
||||
),
|
||||
PatternRule(
|
||||
name=r'delimiter',
|
||||
pattern=r"\(|\)|\[|\]|{|}|,|;|->|=>|=|\?|(?<!:):(?!=:)",
|
||||
pattern=r",|;|->|=>|=|\?|(?<!:):(?!=:)",
|
||||
),
|
||||
PatternRule(
|
||||
name=r'unary_operator',
|
||||
|
|
16
test3.py
16
test3.py
|
@ -1,5 +1,5 @@
|
|||
import sys
|
||||
import lex2, lex2_perl
|
||||
import lex2, lex2_perl, highlight2
|
||||
|
||||
color_list = []
|
||||
color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
|
||||
|
@ -87,15 +87,7 @@ for path in paths:
|
|||
|
||||
grammar = lex2_perl.PerlGrammar()
|
||||
lexer = lex2.Lexer('lexer', grammar)
|
||||
highlighter = highlight2.Highlighter(lexer)
|
||||
|
||||
lexer.lex(lines)
|
||||
y = 0
|
||||
for token in lexer:
|
||||
while token.y > y:
|
||||
sys.stdout.write('\n')
|
||||
y += 1
|
||||
#color_name = token_colors.get(token.name, 'white')
|
||||
color_name = token_colors[token.name]
|
||||
sys.stdout.write(color_dict[color_name])
|
||||
sys.stdout.write(token.string)
|
||||
sys.stdout.write('\n')
|
||||
highlighter.highlight(lines)
|
||||
highlighter.display(token_colors)
|
||||
|
|
Loading…
Reference in New Issue