Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78582 - in sandbox/icl/libs/xplore/br1/sqlbrowser: . gen
From: afojgo_at_[hidden]
Date: 2012-05-24 09:55:00


Author: jofaber
Date: 2012-05-24 09:54:59 EDT (Thu, 24 May 2012)
New Revision: 78582
URL: http://svn.boost.org/trac/boost/changeset/78582

Log:
Worked on Db Generator.
Binary files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/Generatic1.db
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp | 189 +++++++++++++++++++++++++++++++++++++--
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h | 38 +++++++
   sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro | 4
   3 files changed, 212 insertions(+), 19 deletions(-)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Generatic1.db
==============================================================================
Binary files. No diff available.

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp 2012-05-24 09:54:59 EDT (Thu, 24 May 2012)
@@ -15,8 +15,10 @@
 
 void DbGenerator::configure()
 {
- m_iArtists = 1000;
- m_iTitles = 10000;
+ m_iArtists = 10;
+ m_iTitles = 100;
+ m_iAlbums = 50;
+ m_iRecordings = 200;
 }
 
 void DbGenerator::clear()
@@ -37,6 +39,8 @@
 
     //------------------------------------------
     clearDb();
+
+ prepareGeneration();
     generateTables();
     generateTypeData();
 
@@ -63,6 +67,15 @@
 }
 
 
+void DbGenerator::prepareGeneration()
+{
+ //! \note Insert statements are very slowly because they are safe guarded
+ //! by a transaction each enshure data safety in case of havary (e.g. black out).
+ //! PRAGMA synchronous = OFF disables transactions. This greatly speeds up inserts.
+ exec("PRAGMA synchronous = OFF");
+}
+
+
 void DbGenerator::generateTypeData()
 {
     generateTypeTraits();
@@ -77,7 +90,6 @@
 
 void DbGenerator::clearDb()
 {
-
     exec("drop view Album" );
     exec("drop view EdgesMinimal" );
     exec("drop view NamedObjects" );
@@ -166,12 +178,20 @@
     );
 }
 
+//------------------------------------------------------------------------------
+//- Generate Objects
+//------------------------------------------------------------------------------
 void DbGenerator::generateObjects()
 {
     generateArtists(m_iArtists);
     generateTitles(m_iTitles);
+ generateAlbums(m_iAlbums);
+ generateRecordings(m_iRecordings);
 }
 
+//------------------------------------------------------------------------------
+//- Generate Relationships
+//------------------------------------------------------------------------------
 void DbGenerator::generateRelationships()
 {
     generateArtistComposedTitle();
@@ -214,16 +234,48 @@
     return aKey;
 }
 
-
 dag::db::tKey DbGenerator::generateTitle()
 {
     tKey aKey = insertObject();
     insertVertex(aKey, a_title);
- insertVarCharObject(aKey, A_Name, m_aSomeName("T_"));
+ tString aName = m_aSomeName("T_");
+ m_aTitleNames.add(tKey2Name::value_type(aKey, aName));
+
+ insertVarCharObject(aKey, A_Name, aName);
+ insertIntObject(aKey, A_Year, gen::IntGenerator(1960, 2012)());
+ return aKey;
+}
+
+dag::db::tKey DbGenerator::generateRecording(tKey aAlbumKey, tKey aTitleKey)
+{
+ tKey aKey = insertObject();
+ insertVertex(aKey, a_recording);
+ //JODO make name from album & title
+ insertVarCharObject(aKey, A_Name, makeRecordingName(aAlbumKey, aTitleKey));
+ insertIntObject(aKey, A_Year, gen::IntGenerator(1960, 2012)());
+ return aKey;
+}
+
+tString DbGenerator::makeRecordingName(tKey aAlbumKey, tKey aTitleKey)
+{
+ return m_aAlbumNames(aAlbumKey) + "_" + m_aTitleNames(aTitleKey);
+}
+
+dag::db::tKey DbGenerator::generateAlbum()
+{
+ tKey aKey = insertObject();
+ insertVertex(aKey, c_album);
+ tString aName = m_aSomeName("Al_");
+ m_aAlbumNames.add(tKey2Name::value_type(aKey, aName));
+
+ insertVarCharObject(aKey, A_Name, aName);
     insertIntObject(aKey, A_Year, gen::IntGenerator(1960, 2012)());
     return aKey;
 }
 
+
+
+//------------------------------------------------------------------------------
 void DbGenerator::generateArtists(int count)
 {
     for(int idx=0; idx<count; idx++)
@@ -236,14 +288,50 @@
         m_aTitles.add(generateTitle());
 }
 
+void DbGenerator::generateRecordings(int count)
+{
+ int titleCount = m_aTitles.size();
+ int coverRate = count / titleCount;
+ int coverRest = count % titleCount;
+
+ int albumCount = m_aAlbums.size();
+ int albumRate = count / albumCount;
+ int albumRest = count % albumCount;
+
+ tKey aTitleKey = first(m_aTitles);
+ tKey aAlbumKey = first(m_aAlbums);
+
+ for( int idx=1
+ ; idx <= count && contains(m_aTitles, aTitleKey)
+ && contains(m_aAlbums, aAlbumKey)
+ ; idx++)
+ {
+ if(idx % coverRate == 0)
+ ++aTitleKey;
+ if(idx % albumRate == 0)
+ ++aAlbumKey;
+
+ m_aRecordings.add(generateRecording(aAlbumKey, aTitleKey));
+ }
+
+}
+
+void DbGenerator::generateAlbums(int count)
+{
+ for(int idx=0; idx<count; idx++)
+ m_aAlbums.add(generateAlbum());
+}
+
 
+//------------------------------------------------------------------------------
+//- Relationships (Edges)
+//------------------------------------------------------------------------------
 void DbGenerator::generateArtistComposedTitle()
 {
- tKey aKey = insertObject();
     makeComposersRange();
 
     //Every title needs at least one composer.
- for( tKeySet::element_iterator it = elements_begin(m_aTitles)
+ for( tInterKeySet::element_iterator it = elements_begin(m_aTitles)
         ; it != elements_end(m_aTitles); ++it)
     {
         assignComposers(*it);
@@ -265,26 +353,101 @@
     gen::IntGenerator someArtist(m_aComposersRange);
     tKey aArtist1 = someArtist();
 
- tKey aEdgeKey1 = insertObject();
- insertEdge(aEdgeKey1, R_artist_composed_title, aArtist1, aTitle);
+ addComposerToTitle(aArtist1, aTitle);
 
     if(IntGenerator(1,3)() == 3)
     {
         tKey aArtist2 = someArtist();
         if(aArtist2 != aArtist1)
         {
- tKey aEdgeKey2 = insertObject();
- insertEdge(aEdgeKey2, R_artist_composed_title, aArtist2, aTitle);
+ addComposerToTitle(aArtist2, aTitle);
             if(IntGenerator(1,3)() == 3)
             {
- tKey aEdgeKey3 = insertObject();
                 tKey aArtist3 = someArtist();
                 if(aArtist3 != aArtist1 && aArtist3 != aArtist2)
- insertEdge(aEdgeKey3, R_artist_composed_title, aArtist3, aTitle);
+ addComposerToTitle(aArtist3, aTitle);
             }
 
         }
     }
 }
 
+void DbGenerator::addComposerToTitle(tKey aArtistKey, tKey aTitleKey)
+{
+ tKey aEdgeKey = insertObject();
+ insertEdge(aEdgeKey, R_artist_composed_title, aArtistKey, aTitleKey);
+ tKeySet aTitleKeySet;
+ aTitleKeySet.insert(aTitleKey);
+ tKeySet aArtistKeySet;
+ aArtistKeySet.insert(aArtistKey);
+ m_aComposer2Titles.add(std::make_pair(aArtistKey, aTitleKeySet));
+ m_aTitle2Composers.add(std::make_pair(aTitleKey, aArtistKeySet));
+}
+
+
+//------------------------------------------------------------------------------
+void DbGenerator::generateTitleRecordedAsRecording()
+{
+ //Every recording needs at least one title that it is a recording of
+ for( tInterKeySet::element_iterator it = elements_begin(m_aRecordings)
+ ; it != elements_end(m_aRecordings); ++it)
+ {
+ assignTitle(*it);
+ }
+
+ /*
+ //Most recordings are part of an album
+ for( tInterKeySet::element_iterator it = elements_begin(m_aRecordings)
+ ; it != elements_end(m_aRecordings); ++it)
+ {
+ assignAlbum(*it);
+ }
+
+ //Every recording needs at least one performing artist
+ for( tInterKeySet::element_iterator it = elements_begin(m_aRecordings)
+ ; it != elements_end(m_aRecordings); ++it)
+ {
+ assignArtists(*it);
+ }
+ */
+}
+
+// composer -> { titles }
+// title -> { composers }
+
+void DbGenerator::assignTitle(tKey aRecordingKey)
+{
+ gen::IntGenerator someTitle(hull(m_aTitles));
+ tKey aTitleKey = someTitle();
+
+ //JODO Make the construction of entities more realistic
+ //tKey aComposerKey = getComposer(aTitleKey);
+ //tKey aSomeAlbumKey = getSomeComposerAlbum();
+
+ tKey aEdgeKey = insertObject();
+ insertEdge(aEdgeKey, R_title_recorded_as_record, aTitleKey, aRecordingKey);
+}
+
+void DbGenerator::assignAlbum(tKey aRecordingKey)
+{
+ gen::IntGenerator someAlbum(hull(m_aAlbums));
+ tKey aAlbumKey = someAlbum();
+
+ tKey aEdgeKey = insertObject();
+ insertEdge(aEdgeKey, R_album_contains_record, aAlbumKey, aRecordingKey);
+}
+
+
+/*
+void DbGenerator::generateAlbumContainsRecording()
+{
+ //Every title needs at least one composer.
+ for( tInterKeySet::element_iterator it = elements_begin(m_aTitles)
+ ; it != elements_end(m_aTitles); ++it)
+ {
+ assignComposers(*it);
+ }
+
+}
+*/
 

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h 2012-05-24 09:54:59 EDT (Thu, 24 May 2012)
@@ -6,6 +6,7 @@
 #pragma once
 
 
+#include <boost/icl/map.hpp>
 #include <boost/icl/interval_set.hpp>
 
 #include <QtSql>
@@ -24,8 +25,12 @@
     typedef dag::db::tKey tKey;
     typedef unsigned int tObjectType;
     typedef unsigned int tAttribute;
- typedef boost::icl::interval_set<tKey> tKeySet;
- typedef tKeySet::interval_type tInterval;
+ typedef std::set<tKey> tKeySet;
+ typedef boost::icl::map<tKey, tKeySet> tKey2Keys;
+ typedef boost::icl::map<tKey, tString> tKey2Name;
+
+ typedef boost::icl::interval_set<tKey> tInterKeySet;
+ typedef tInterKeySet::interval_type tInterval;
 
     enum {
         a_text = 1
@@ -83,13 +88,20 @@
 
     void generateArtists(int);
     void generateTitles(int);
+ void generateRecordings(int);
+ void generateAlbums(int);
 
     void generateArtistComposedTitle();
+ void generateTitleRecordedAsRecording();
+ void generateAlbumContainsRecording();
 
 private:
     void configure();
     bool exec(const tString& sql);
 
+ void prepareGeneration();
+
+
     //void generateTypeData();
     void generateTypeTraits();
     void generateObjectTypes();
@@ -104,13 +116,22 @@
 
     tKey generateArtist();
     tKey generateTitle();
+ tKey generateRecording(tKey aAlbumKey, tKey aTitleKey);
+ tKey generateAlbum();
 
     void makeComposersRange();
     void assignComposers(tKey aTitle);
+ void addComposerToTitle(tKey aArtistKey, tKey aTitleKey);
+
+ void assignTitle(tKey aRecordingKey);
+ void assignAlbum(tKey aRecordingKey);
+ tString makeRecordingName(tKey aAlbumKey, tKey aTitleKey);
 
 private:
     int m_iArtists;
     int m_iTitles;
+ int m_iAlbums;
+ int m_iRecordings;
 
     QSqlDatabase m_aDb;
     QSqlQuery m_aQuery;
@@ -118,9 +139,18 @@
     tString m_aFailingSql;
     NameGenerator m_aSomeName;
 
- tKeySet m_aArtists;
+ tInterKeySet m_aArtists;
+ tInterKeySet m_aTitles;
+ tInterKeySet m_aRecordings;
+ tInterKeySet m_aAlbums;
+
     tInterval m_aComposersRange;
- tKeySet m_aTitles;
+
+ tKey2Keys m_aComposer2Titles;
+ tKey2Keys m_aTitle2Composers;
+
+ tKey2Name m_aTitleNames;
+ tKey2Name m_aAlbumNames;
 };
 
 } // namespace data

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro 2012-05-24 09:54:59 EDT (Thu, 24 May 2012)
@@ -3,8 +3,8 @@
 
 QT += sql
 
-INCLUDEPATH += /cygwin/home/jofa/dev/boost/branches/release
-#INCLUDEPATH += C:\NIBuild\3rdparty\boost-1.48.0
+#INCLUDEPATH += /cygwin/home/jofa/dev/boost/branches/release
+INCLUDEPATH += C:\NIBuild\3rdparty\boost-1.48.0
 
 HEADERS = browser.h connectionwidget.h qsqlconnectiondialog.h \
     exttableview.h \


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk