본문으로 건너뛰기
← 모든 예제

예제 23

Charts by symbol

a report of the workspace by symbol — how many charts each

분류
Workspace: 차트와 패널을 읽거나 변경
권한
workspace.read
실행하기 전에
a terminal window
하는 일
none
실행 방법
in TTT, open the T0 Editor, open this file, grant workspace.read,
언어
>=0.1.1, <0.2.0
호스트
>=0.1.1, <0.2.0
필요한 것
workspace >=0.1.1, <0.2.0

소스

// Purpose: a report of the workspace by symbol — how many charts each
// symbol has and at which timeframes — and of the panels that are not
// charts. Changes nothing.
// Category: workspace
// Permissions: workspace.read
// Preconditions: a terminal window
// Side effects: none
// Run: in TTT, open the T0 Editor, open this file, grant workspace.read,
// Run.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.1, <0.2.0";
requires "workspace" ">=0.1.1, <0.2.0";
import std.list;

fn main() {
    let mut seen: List<String> = [];
    for c in workspace.charts() {
        if !list.contains(seen, c.symbol) {
            seen.push(c.symbol);
        }
    }
    for symbol in seen {
        let mut timeframes: List<String> = [];
        for c in workspace.charts() {
            if c.symbol == symbol {
                timeframes.push(c.timeframe);
            }
        }
        print(symbol + ": " + to_string(timeframes.len()) + " chart(s) " + to_string(timeframes));
    }
    let mut others = 0;
    for p in workspace.panels() {
        if p.kind != "Chart" {
            others = others + 1;
            print("panel: " + p.title);
        }
    }
    print(to_string(others) + " panel(s) besides the charts");
}