To predict future sales we have used a simple combination of least-squares method and weekly averages. For the daily prediction we use two different methods that will both be displayed to the user. If, for example, we need to predict sales for a Monday, we gather data from the last 5 Mondays and run a least-squares algorithm on that data set to estimate sale. The second method is the same except we use the last three days, for example Monday, Tuesday and Wednesday if we need to predict sales for Thursday and then run the least-squares algorithm on the data set. This enables us to estimate sales for a specific day using either data from that specific day of the week or from the adjacent days. The prediction can be displayed for a given interval, depending on the interval we will run the least-squares algorithm on a larger data set.
23.5.1
Least-squares method
The least-squares method can be used to, among other things, calculate a trend line (best line), through a set of points, from a given data set. A straight line is of the formy=mx+b. The formulas we use for our prediction is:
m = n P xy−(Px)(Py) nPx2 −(Px)2 b = P y−mPx n
Persistence
As mentioned earlier we have decided to focus our development on persistence. Persistence means that after the program has ended, data persists and can be loaded the next time the program runs. Our data is in the form of objects, which we need a method and place to store. There are a lot of ways of making objects persist. Objects can be stored in a single file, in multiple files or in a database. We have chosen that our means of persistence should be interchangeable, or in other words, different data storing methods should be usable for our system without changing any program code, outside the persistence layer. To enable communication with different databases we have chosen JDBC and for testing purposes we have chosen the PostgreSQL DBMS. In the following chapter we will describe the technologies used in our system and explain our choices.
24.1
Database Management Systems
A Database1 Management System (DBMS)[5] is a program designed to create,
manage and maintain a database through a database server, which may or may not be a part of the DBMS. A DBMS is typically a program that administrates func- tionality between a database application (user program) and the database server (database). In most cases the DBMS and the database server will be bundled, as most DBMSs are designed for only one database and database server. The structure of a typical database scheme is:
User program-Connectivity framework(JDBC/ODBC)-DBMS
tional and object oriented will be described shortly. We have chosen to focus our research on these two because of their advantages regarding the task at hand, those advantages will be discussed later.
24.1.1
Relational Database Management Systems
A Relational DBMS (RDBMS) is is DBMS based on the relational model[2]. There are few true RDBMSs, these few are called TRDBMS for True Relational DBMS. The definition of a TRDBMS is that it must adhere to Codd’s 12 rules[3], which is a collection of rules 1 through 12 that was introduced by Edgar F. Codd, the father of the relational model. Some DBMSs claim to be relational without actually being so in the original sense of the meaning. These “fake” RDBMSs do not adhere to all twelve rules, but usually some of the rules.
A common, but flawed, belief is, that relational databases are relational if they store data as rows2in a table. Such a database could be PostgreSQL, which does exactly
that. While databases that store data in tables, rows and columns often are called relational, those characteristics does not make it true. All popular RDMSs today use SQL as their query language. One such RDBMS is PostgreSQL which in its current version[8] has support for both SQL-92 and SQL-99. SQL-92 has been the default industry standard since 1992[9] and is a subset of SQL-99.
Object mapping
It is not directly possible to store objects in a relational database, because of the very different structure of the two. Therefore we need to map the objects onto the tables of the relational database. This is done by using or developing a system that turns an object into the proper SQL-statements to store that object in a relational database. Such a system could be, for example, JDO3. Such systems are often as slow as the objects are complex.
24.1.2
Object Oriented Database Management System
An OODBMS4 is a database management system designed for managing object
oriented databases. This database type can be used to put objects directly in the 2originally tuples in the relational model, but often called rows anyway
3Java Data Objects
bles. Doing this has the advantage that the programmer does not need to think about getting the objects into a relational database. Some of the major disadvantage of this type of database is that it lacks the foundation that the RDBMSs have, such as a large variety of tools, the power and simplicity of SQL and last but not least, the well proven mathematical base that the relational model provides through relational calculus.[1]
24.1.3
RDBMS vs. OODBMS
When taking the above into account it is clear that there are advantages and disad- vantages to both RDBMSs and OODBMSs. We believe that the main advantages and disadvantages are:
Regarding the RDBMS • Advantages: – Structural flexibility – Good foundation • Disadvantages: – Object mapping
– Need toJOIN tables to recreate objects
– Need for primary keys
Regarding the OODBMS
• Advantages:
– No need for query language – Faster queries
– No need for primary keys as they are “built into” the objects
• Disadvantages:
We have weighed out the advantages and disadvantages of the two types and have concluded that although it has disadvantages, the RDBMS is clearly easier to use in our case as it is the technology that we are the most familiar with.