Skip to content

Commit

Permalink
Changed tslint to comply with clang and the google style guide for ty…
Browse files Browse the repository at this point in the history
…pescript. (max line length = 80 and single quotes). Then updated all typescript files to comply with the tslint.

Change: 120750153
  • Loading branch information
dsmilkov authored and tensorflower-gardener committed Apr 25, 2016
1 parent 24e1e6c commit a8af8bc
Show file tree
Hide file tree
Showing 41 changed files with 1,639 additions and 1,541 deletions.
26 changes: 15 additions & 11 deletions tensorflow/tensorboard/components/tf-backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

module TF.Backend {
// TODO(cassandrax): Remove this interface.
export interface RunEnumeration {
Expand All @@ -23,7 +24,6 @@ module TF.Backend {
run_metadata: string[];
}


// TODO(cassandrax): Remove this interface.
export interface RunsResponse { [runName: string]: RunEnumeration; }

Expand All @@ -48,9 +48,13 @@ module TF.Backend {
bucketCounts: number[];
}

export interface HistogramBin { x: number, dx: number, y: number }
export interface HistogramBin {
x: number;
dx: number;
y: number;
}
export type HistogramSeriesDatum = HistogramSeries & Datum;
export interface HistogramSeries { bins: HistogramBin[] }
export interface HistogramSeries { bins: HistogramBin[]; }

export type ImageDatum = Datum & Image;
export interface Image {
Expand All @@ -59,7 +63,6 @@ module TF.Backend {
url: string;
}


export var TYPES = [
'scalar', 'histogram', 'compressedHistogram', 'graph', 'image',
'runMetadata'
Expand Down Expand Up @@ -296,14 +299,15 @@ module TF.Backend {
* to visualize. When visualizing histograms, having the left edge and width
* makes things quite a bit easier.
*
* @param {histogram} Histogram - A histogram from tensorboard backend.
* @return {HistogramBin[]} - Each bin has an x (left edge), a dx (width), and a y (count).
* @param histogram A histogram from tensorboard backend.
* @return A histogram bin. Each bin has an x (left edge), a dx (width),
* and a y (count).
*
* If given rightedges are inclusive, then these left edges (x) are exclusive.
*/
export function convertBins(histogram: Histogram) {
if (histogram.bucketRightEdges.length !== histogram.bucketCounts.length) {
throw(new Error('Edges and counts are of different lengths.'))
throw(new Error('Edges and counts are of different lengths.'));
}

var previousRightEdge = histogram.min;
Expand All @@ -325,10 +329,10 @@ module TF.Backend {
}

/**
* The following interfaces (TupleData, HistogramTuple,
* CompressedHistogramTuple, and ImageMetadata) describe how the data is sent
* over from the backend; the numbers are wall_time then step
*/
* The following interfaces (TupleData, HistogramTuple,
* CompressedHistogramTuple, and ImageMetadata) describe how the data is sent
* over from the backend; the numbers are wall_time then step
*/
type TupleData<T> = [number, number, T];

// Min, Max, nItems, Sum, Sum_Squares, right edges of buckets, nItems in
Expand Down
46 changes: 24 additions & 22 deletions tensorflow/tensorboard/components/tf-backend/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,32 @@ module TF.Backend {
*/
backendReload: function() {
if (this.dataType == null) {
throw new Error("TF.Backend.Behavior: Need a dataType to reload.");
throw new Error('TF.Backend.Behavior: Need a dataType to reload.');
}
if (this.backend == null) {
throw new Error("TF.Backend.Behavior: Need a backend to reload.");
throw new Error('TF.Backend.Behavior: Need a backend to reload.');
}
var runsRoute = this.backend[this.dataType + "Runs"].bind(this.backend);
this._setLoadState("pending");
return runsRoute().then((x) => {
this._setLoadState("loaded");
if (_.isEqual(x, this.run2tag)) {
// If x and run2tag are equal, let's avoid updating everything
// since that can needlessly trigger run changes, reloads, etc
return x;
}
this._setRun2tag(x);
var tags = TF.Backend.getTags(x);
this._setDataNotFound(tags.length === 0);
this._setTags(tags);
this._setRuns(TF.Backend.getRuns(x));
return x;
}, (fail) => {
this._setLoadState("failure");
return fail;
});
var runsRoute = this.backend[this.dataType + 'Runs'].bind(this.backend);
this._setLoadState('pending');
return runsRoute().then(
(x) => {
this._setLoadState('loaded');
if (_.isEqual(x, this.run2tag)) {
// If x and run2tag are equal, let's avoid updating everything
// since that can needlessly trigger run changes, reloads, etc
return x;
}
this._setRun2tag(x);
var tags = TF.Backend.getTags(x);
this._setDataNotFound(tags.length === 0);
this._setTags(tags);
this._setRuns(TF.Backend.getRuns(x));
return x;
},
(fail) => {
this._setLoadState('failure');
return fail;
});
},
_do_autoLoad: function(type, backend, autoLoad) {
if (autoLoad) {
Expand All @@ -121,7 +123,7 @@ module TF.Backend {
},
_throwErrorOnUnrecognizedType: function(dataType) {
if (TF.Backend.TYPES.indexOf(dataType) === -1) {
throw new Error("TF.Backend.Behavior: Unknown dataType " + dataType);
throw new Error('TF.Backend.Behavior: Unknown dataType ' + dataType);
}
},
};
Expand Down
81 changes: 45 additions & 36 deletions tensorflow/tensorboard/components/tf-backend/requestManager.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/* Copyright 2015 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

module TF.Backend {
interface ResolveReject {resolve: Function; reject: Function; }
/*
* Manages many fetch requests. Launches up to nSimultaneousRequests
* simultaneously, and maintains a LIFO queue of requests to process when
* more urls are requested than can be handled at once. The queue can be cleared.
*
* When a request is made, a Promise is returned which resolves with the parsed
* JSON result from the request.
*/

/**
* Manages many fetch requests. Launches up to nSimultaneousRequests
* simultaneously, and maintains a LIFO queue of requests to process when
* more urls are requested than can be handled at once. The queue can be
* cleared.
*
* When a request is made, a Promise is returned which resolves with the
* parsed JSON result from the request.
*/
export class RequestCancellationError extends Error {
public name = "RequestCancellationError";
public name = 'RequestCancellationError';
}

export class RequestNetworkError extends Error {
Expand All @@ -36,7 +36,7 @@ module TF.Backend {
constructor(req: XMLHttpRequest, url) {
super();
this.message = `RequestNetworkError: ${req.status} at ${url}`;
this.name = "RequestNetworkError";
this.name = 'RequestNetworkError';
this.req = req;
this.url = url;
}
Expand All @@ -58,31 +58,39 @@ module TF.Backend {
/* Gives a promise that loads assets from given url (respects queuing) */
public request(url: string): Promise<any> {
var promise = new Promise((resolve, reject) => {
var resolver = {resolve: resolve, reject: reject};
this._queue.push(resolver);
this.launchRequests();
}).then(() => {
return this.promiseWithRetries(url, this._maxRetries);
}).then((response) => {
// Success - Let's free space for another active reqest, and launch it
this._nActiveRequests--;
this.launchRequests();
return response;
}, (rejection) => {
if (rejection.name === "RequestNetworkError") {
// If we failed due to network error, we should decrement
// _nActiveRequests because this request was active
this._nActiveRequests--;
this.launchRequests();
}
return Promise.reject(rejection);
});
var resolver = {resolve: resolve, reject: reject};
this._queue.push(resolver);
this.launchRequests();
})
.then(() => {
return this.promiseWithRetries(url, this._maxRetries);
})
.then(
(response) => {
// Success - Let's free space for another active
// reqest, and launch it
this._nActiveRequests--;
this.launchRequests();
return response;
},
(rejection) => {
if (rejection.name === 'RequestNetworkError') {
// If we failed due to network error, we should
// decrement
// _nActiveRequests because this request was
// active
this._nActiveRequests--;
this.launchRequests();
}
return Promise.reject(rejection);
});
return promise;
}

public clearQueue() {
while (this._queue.length > 0) {
this._queue.pop().reject(new RequestCancellationError("Request cancelled by clearQueue"));
this._queue.pop().reject(
new RequestCancellationError('Request cancelled by clearQueue'));
}
}

Expand All @@ -97,7 +105,8 @@ module TF.Backend {
}

private launchRequests() {
while (this._nActiveRequests < this._nSimultaneousRequests && this._queue.length > 0) {
while (this._nActiveRequests < this._nSimultaneousRequests &&
this._queue.length > 0) {
this._nActiveRequests++;
this._queue.pop().resolve();
}
Expand All @@ -107,7 +116,7 @@ module TF.Backend {
* Try to request a given URL using overwritable _promiseFromUrl method.
* If the request fails for any reason, we will retry up to maxRetries
* times. In practice, this will help us paper over transient network issues
* like "502 Bad Gateway".
* like '502 Bad Gateway'.
* By default, Chrome displays network errors in console, so
* the user will be able to tell when the requests are failing. I think this
* is a feature, if the request failures and retries are causing any
Expand All @@ -129,7 +138,7 @@ module TF.Backend {
protected _promiseFromUrl(url) {
return new Promise((resolve, reject) => {
var req = new XMLHttpRequest();
req.open("GET", url);
req.open('GET', url);
req.onload = function() {
if (req.status === 200) {
resolve(JSON.parse(req.responseText));
Expand Down
50 changes: 27 additions & 23 deletions tensorflow/tensorboard/components/tf-backend/router.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* Copyright 2015 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Expand All @@ -32,54 +32,58 @@ module TF.Backend {
* @param dataDir {string} The base prefix for finding data on server.
* @param demoMode {boolean} Whether to modify urls for filesystem demo usage.
*/
export function router(dataDir = "/data", demoMode = false): Router {
export function router(dataDir = '/data', demoMode = false): Router {
var clean = demoMode ? demoify : (x) => x;
if (dataDir[dataDir.length - 1] === "/") {
if (dataDir[dataDir.length - 1] === '/') {
dataDir = dataDir.slice(0, dataDir.length - 1);
}
function standardRoute(route: string): ((tag: string, run: string) => string) {
function standardRoute(route: string):
((tag: string, run: string) => string) {
return function(tag: string, run: string): string {
var url = dataDir + "/" + route + clean(queryEncoder({tag: tag, run: run}));
var url =
dataDir + '/' + route + clean(queryEncoder({tag: tag, run: run}));
if (demoMode) {
url += ".json";
url += '.json';
}
return url;
};
}
function individualImageUrl(query: string) {
var url = dataDir + "/" + clean("individualImage?" + query);
var url = dataDir + '/' + clean('individualImage?' + query);
if (demoMode) {
url += ".png";
url += '.png';
}
return url;
}
function graphUrl(run: string, limit_attr_size?: number,
large_attrs_key?: string) {
let query_params = [["run", clean(run)]];
let query_params = [['run', clean(run)]];
if (limit_attr_size != null && !demoMode) {
query_params.push(["limit_attr_size", String(limit_attr_size)]);
query_params.push(['limit_attr_size', String(limit_attr_size)]);
}
if (large_attrs_key != null && !demoMode) {
query_params.push(["large_attrs_key", large_attrs_key]);
query_params.push(['large_attrs_key', large_attrs_key]);
}
let query = query_params.map(param => {
return param[0] + "=" + encodeURIComponent(param[1]);
}).join("&");
var url = dataDir + "/graph" + clean("?" + query);
let query = query_params
.map(param => {
return param[0] + '=' + encodeURIComponent(param[1]);
})
.join('&');
var url = dataDir + '/graph' + clean('?' + query);
if (demoMode) {
url += ".pbtxt";
url += '.pbtxt';
}
return url;
}
return {
runs: () => dataDir + "/runs" + (demoMode ? ".json" : ""),
runs: () => dataDir + '/runs' + (demoMode ? '.json' : ''),
individualImage: individualImageUrl,
graph: graphUrl,
scalars: standardRoute("scalars"),
histograms: standardRoute("histograms"),
compressedHistograms: standardRoute("compressedHistograms"),
images: standardRoute("images"),
runMetadata: standardRoute("run_metadata"),
scalars: standardRoute('scalars'),
histograms: standardRoute('histograms'),
compressedHistograms: standardRoute('compressedHistograms'),
images: standardRoute('images'),
runMetadata: standardRoute('run_metadata'),
};
};
}
Loading

0 comments on commit a8af8bc

Please sign in to comment.