Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (c) 2016 Google Inc. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you
      5  * may not use this file except in compliance with the License. You may
      6  * obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
     13  * implied. See the License for the specific language governing
     14  * permissions and limitations under the License.
     15  */
     16 
     17 package com.android.vts.util;
     18 
     19 import com.android.vts.entity.ProfilingPointRunEntity;
     20 import com.google.gson.JsonObject;
     21 import com.google.gson.JsonPrimitive;
     22 
     23 /** Helper object for describing graph data. */
     24 public abstract class Graph {
     25     public static final String VALUE_KEY = "values";
     26     public static final String X_LABEL_KEY = "x_label";
     27     public static final String Y_LABEL_KEY = "y_label";
     28     public static final String IDS_KEY = "ids";
     29     public static final String NAME_KEY = "name";
     30     public static final String TYPE_KEY = "type";
     31 
     32     public static enum GraphType { LINE_GRAPH, HISTOGRAM, BOX_PLOT }
     33 
     34     /**
     35      * Get the graph type.
     36      *
     37      * @return The graph type.
     38      */
     39     public abstract GraphType getType();
     40 
     41     /**
     42      * Get the x axis label.
     43      *
     44      * @return The x axis label.
     45      */
     46     public abstract String getXLabel();
     47 
     48     /**
     49      * Get the y axis label.
     50      *
     51      * @return The y axis label.
     52      */
     53     public abstract String getYLabel();
     54 
     55     /**
     56      * Get the name of the graph.
     57      *
     58      * @return The name of the graph.
     59      */
     60     public abstract String getName();
     61 
     62     /**
     63      * Get the number of data points stored in the graph.
     64      *
     65      * @return The number of data points stored in the graph.
     66      */
     67     public abstract int size();
     68 
     69     /**
     70      * Add data to the graph.
     71      *
     72      * @param id The name of the graph.
     73      * @param profilingPoint The ProfilingPointEntity containing data to add.
     74      */
     75     public abstract void addData(String id, ProfilingPointRunEntity profilingPoint);
     76 
     77     /**
     78      * Serializes the graph to json format.
     79      *
     80      * @return A JsonElement object representing the graph object.
     81      */
     82     public JsonObject toJson() {
     83         JsonObject json = new JsonObject();
     84         json.add(X_LABEL_KEY, new JsonPrimitive(getXLabel()));
     85         json.add(Y_LABEL_KEY, new JsonPrimitive(getYLabel()));
     86         json.add(NAME_KEY, new JsonPrimitive(getName()));
     87         json.add(TYPE_KEY, new JsonPrimitive(getType().toString()));
     88         return json;
     89     }
     90 }
     91