未验证 提交 dbc68507 编写于 作者: J Jeff Wang 提交者: GitHub

Connect text feature with back end (#341)

* Add manual Save feature.

* Fix the incorrect style

* Add feature to record Text

* Create a simple UI for text preview.

* Connect frontend with backend text data

* Move a constant from parameter to the body.
Remove test log
上级 ce807324
......@@ -129,7 +129,6 @@ export default {
});
getRuns().then(({errno, data}) => {
console.log(data);
this.runsArray = data;
this.config.runs = data;
});
......
......@@ -284,8 +284,13 @@ private:
TabletReader reader_;
};
/*
* Text component writer
*/
struct Text {
Text(Tablet tablet) : tablet_(tablet) {}
Text(Tablet tablet) : tablet_(tablet) {
tablet_.SetType(Tablet::Type::kText);
}
void SetCaption(const std::string cap) {
tablet_.SetCaptions(std::vector<std::string>({cap}));
}
......@@ -304,6 +309,9 @@ private:
Tablet tablet_;
};
/*
* Text reader.
*/
struct TextReader {
TextReader(TabletReader reader) : reader_(reader) {}
......
......@@ -159,7 +159,44 @@ def get_histogram_tags(storage):
return get_tags(storage, 'histogram')
def get_histogram(storage, mode, tag, num_samples=100):
def get_texts_tags(storage):
return get_tags(storage, 'text')
def get_texts(storage, mode, tag, num_records=100):
with storage.mode(mode) as reader:
texts = reader.text(tag)
records = texts.records()
ids = texts.ids()
timestamps = texts.timestamps()
data = list(zip(timestamps, ids, records))
data_size = len(data)
if data_size <= num_records:
return data
span = float(data_size) / (num_records - 1)
span_offset = 0
data_idx = int(span_offset * span)
sampled_data = []
while data_idx < data_size:
sampled_data.append(data[data_size - data_idx - 1])
span_offset += 1
data_idx = int(span_offset * span)
sampled_data.append(data[0])
res = sampled_data[::-1]
# TODO(Superjomn) some bug here, sometimes there are zero here.
if res[-1] == 0.:
res = res[:-1]
return res
def get_histogram(storage, mode, tag):
with storage.mode(mode) as reader:
histogram = reader.histogram(tag)
res = []
......@@ -182,6 +219,9 @@ def get_histogram(storage, mode, tag, num_samples=100):
instance = record.instance(j)
data.append(
[instance.left(), instance.right(), instance.frequency()])
# num_samples: We will only return 100 samples.
num_samples = 100
if len(res) < num_samples:
return res
......
......@@ -171,6 +171,14 @@ def histogram_tags():
return Response(json.dumps(result), mimetype='application/json')
@app.route("/data/plugin/texts/tags")
def texts_tags():
data = cache_get("/data/plugin/texts/tags", try_call,
lib.get_texts_tags, log_reader)
result = gen_result(0, "", data)
return Response(json.dumps(result), mimetype='application/json')
@app.route('/data/plugin/scalars/scalars')
def scalars():
run = request.args.get('run')
......@@ -219,6 +227,16 @@ def histogram():
return Response(json.dumps(result), mimetype='application/json')
@app.route('/data/plugin/texts/texts')
def texts():
run = request.args.get('run')
tag = request.args.get('tag')
key = os.path.join('/data/plugin/texts/texts', run, tag)
data = cache_get(key, try_call, lib.get_texts, log_reader, run, tag)
result = gen_result(0, "", data)
return Response(json.dumps(result), mimetype='application/json')
@app.route('/data/plugin/graphs/graph')
def graph():
# TODO(ChunweiYan) need to add a config for whether have graph.
......
......@@ -107,6 +107,7 @@ message Tablet {
kScalar = 0;
kHistogram = 1;
kImage = 2;
kText = 3;
}
// The unique identification for this `Tablet`. VisualDL will have no the
// concept of FileWriter like TB. It will store all the tablets in a single
......
......@@ -29,7 +29,13 @@ struct TabletReader;
* Tablet is a helper for operations on storage::Tablet.
*/
struct Tablet {
enum Type { kScalar = 0, kHistogram = 1, kImage = 2, kUnknown = -1 };
enum Type {
kScalar = 0,
kHistogram = 1,
kImage = 2,
kText = 3,
kUnknown = -1
};
DECL_GUARD(Tablet);
......@@ -46,6 +52,9 @@ struct Tablet {
if (name == "image") {
return kImage;
}
if (name == "text") {
return kText;
}
LOG(ERROR) << "unknown component: " << name;
return kUnknown;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册