Как заполнить временной ряд OrientDB?

Я хочу создать временной ряд OrientDB год -> месяц -> день -> час -> минута -> секунда.

Пример на вики OrientDB показывает только как создавать классы и как управлять поиском.

Я попытался заполнить свой график, используя этот код , но этот подход требует более 2 минут, если он ограничен часами, как сказал другой пользователь здесь . На уровне секунд аналогичный метод требует около 12 часов.

Это нормально? Есть ли лучший подход? Спасибо всем, кто ответит на мой вопрос.

PS: я уже прочитал слайды Милана 2014, но это только объясняет структура (что у меня есть ясно) и способ получить данные.


person Stefano    schedule 08.04.2016    source источник


Ответы (1)


Можете ли вы попробовать с этим кодом?

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

public class TimesSeriesMain {

    public static void main(String[] args) {

        OServerAdmin serverAdmin;
        try {
            serverAdmin = new OServerAdmin("remote:localhost/myTimeSeries").connect("root", "root");
            if(!serverAdmin.existsDatabase()){ 

                serverAdmin.createDatabase("myTimeSeries", "graph", "plocal");

                OrientGraphNoTx graph_c=new OrientGraphNoTx("remote:localhost/myTimeSeries");

                OClass hour_c=graph_c.createVertexType("Hour", "V");
                hour_c.createProperty("value", OType.INTEGER);

                OClass day_c=graph_c.createVertexType("Day", "V");
                day_c.createProperty("hour", OType.LINKSET, hour_c);

                OClass month_c=graph_c.createVertexType("Month", "V");
                month_c.createProperty("day", OType.LINKMAP, day_c);

                OClass year_c=graph_c.createVertexType("Year", "V");
                year_c.createProperty("value", OType.INTEGER);
                year_c.createProperty("month", OType.LINKMAP, month_c);

                graph_c.shutdown();

                OrientGraph graph=new OrientGraph("remote:localhost/myTimeSeries"); 

                long start = System.currentTimeMillis();

                for (int yy = 2015; yy < 2016; yy++){           
                    Map<Integer, OrientVertex> months = new HashMap<>();
                    for (int mm = 0; mm < 12; mm++){
                        Map<Integer, OrientVertex> days = new HashMap<>();
                        for (int dd = 1; dd < 32; dd++){
                            List<OrientVertex> hours = new ArrayList<OrientVertex>();
                            for (int i = 0; i < 24; i++){
                                OrientVertex hour=graph.addVertex("class:Hour");
                                hour.setProperty("value",i);
                                hours.add(hour);
                            }
                            OrientVertex day=graph.addVertex("class:Day");
                            day.setProperties("hour",hours);
                            days.put(dd,day);
                        }
                        OrientVertex month=graph.addVertex("class:Month");
                        month.setProperties("day",days);
                        months.put(mm,month);
                    }
                    OrientVertex year=graph.addVertex("class:Year");
                    year.setProperties("value",yy);
                    year.setProperties("month",months);    
                }

                long end=System.currentTimeMillis();

                System.out.println(((end-start)) + " millisec") ;

                graph.shutdown();
            }
        }           
        catch(Exception e){
            System.out.println(e);
        }   
    }
}

Надеюсь, поможет.

person Alessandro Rota    schedule 08.04.2016
comment
Большое спасибо за ваш комментарий. Изменение скорости впечатляет (262 мс). Почему так сильно меняется? - person Stefano; 11.04.2016