-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.ts
144 lines (113 loc) · 3.87 KB
/
filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { test_driver } from "./test_driver.ts";
import type { Introspector,CallbackOutput,CallbackInput,iFrame,Accumulator,Accumulated } from "./introspector.ts";
//import type * as dataForge from "npm:[email protected]"
// export function add_to_frame(_results:string,
// name:string,
// value:string):void {
// console.log(name,value);
// }
export function find_calls(_event:string,
_filter:string):void {
}
//(event: any) => DataFrame<number, never>
// Define the type for the accumulator instance
interface NameCount {
name: string;
count: number;
}
// Create a singleton functor with many properties
function createAccumulator(): Accumulator {
const resultsList: Accumulated[] = [];
// the function returned
function accumulator(value: Accumulated): Accumulated {
resultsList.push(value);
return value;
}
function getResults(): Accumulated[] {
return resultsList;
}
function renderHtml(): string {
const html = resultsList.map((result) => `<p>${result}</p>`).join('');
return `<html><body>${html}</body></html>`;
}
function renderJson(): string {
return JSON.stringify(resultsList, null, 2);
}
function renderConsole(): void {
console.log('Accumulator Results:');
resultsList.forEach((result) => console.log(result));
}
accumulator.results = getResults;
accumulator.renderHtml = renderHtml;
accumulator.renderJson = renderJson;
accumulator.renderConsole = renderConsole;
return accumulator;
}
// Create a singleton functor with many properties
function createAccumulated(value:NameCount): Accumulated {
let _result: NameCount=value;
function accumulator(value: NameCount): NameCount {
_result = value;
return value;
}
function getResult(): NameCount {
return _result;
}
function renderHtml(): string {
const html = `<p>${JSON.stringify(_result)}</p>`;
return `<html><body>${html}</body></html>`;
}
function renderJson(): string {
return JSON.stringify(_result, null, 2);
}
function renderConsole(): void {
console.log('Accumulator Results:');
console.log(_result);
}
accumulator.results = getResult;
accumulator.renderHtml = renderHtml;
accumulator.renderJson = renderJson;
accumulator.renderConsole = renderConsole;
return accumulator;
}
// Create a singleton instance of the accumulator
const nameCountAccumulator = createAccumulator();
export function test_frame():void{
console.log("hello test frame");
// var data_list = [];
//var empty_frame1 = new dataForge.DataFrame([]);
function filter_function_name(_frame:iFrame):boolean {
//console.log("filter"+frame);
return true;
}
// let visitor2 = <Introspector>function (event:CallbackInput) {
// return {name:"foo"} as CallbackOutput;
//}
const visitor = <Introspector>function (_event: CallbackInput) : CallbackOutput{
console.log("visitor");
//function visit_function_name(function_name:string, function_value:any):void {
// add_to_frame(empty_frame,function_name, function_value);
//}
return {name:"fixme"};
};
visitor.filter_current_value= filter_function_name; // save part of the callback
visitor.accumulator = createAccumulator();
visitor.debug= function(x:string):CallbackOutput{
//console.log("debug",x);
//const callback =foo;
const a = createAccumulated({count:1,name:x});
//a[x]=1;
//let newRow = new dataForge.DataFrame([a]);
//empty_frame1 = empty_frame1.concat(newRow);
visitor.accumulator(a);
//empty_frame.count()
//console.log("frame count",empty_frame.count());
return {name:x};
}
//console.log("frame count before",empty_frame);
// console.log("frame count",empty_frame1.count());
test_driver(visitor);
//var empty_frame1 = new dataForge.DataFrame(data_list);
//console.log("frame count after",empty_frame);
//console.log("frame count",empty_frame1.count());
}// test frame