Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
udayRage committed Nov 24, 2023
1 parent 3251b14 commit 5d8035a
Show file tree
Hide file tree
Showing 68 changed files with 425 additions and 426 deletions.
8 changes: 4 additions & 4 deletions PAMI/extras/DF2DB/DF2DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from PAMI.extras.DF2DB.DenseFormatDF2DB import *
from PAMI.extras.DF2DB.SparseFormatDF2DB import *
from PAMI.extras.DF2DB.denseDF2DB import *
from PAMI.extras.DF2DB.sparseDF2DB import *
import sys

class DF2DB:
Expand Down Expand Up @@ -76,9 +76,9 @@ def __init__(self, inputDF, thresholdValue, condition, DFtype='sparse') -> None:
self.condition = condition
self.DFtype = DFtype.lower()
if DFtype == 'sparse':
self.DF2DB = sparseFormatDF2DB(self.inputDF, self.condition, self.thresholdValue)
self.DF2DB = sparseDF2DB(self.inputDF, self.condition, self.thresholdValue)
elif DFtype == 'dense':
self.DF2DB = DenseFormatDF2DB(self.inputDF, self.condition, self.thresholdValue)
self.DF2DB = denseDF2DB(self.inputDF, self.condition, self.thresholdValue)
else:
raise Exception('DF type should be sparse or dense')

Expand Down
8 changes: 4 additions & 4 deletions PAMI/extras/DF2DB/DF2DBPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from PAMI.extras.DF2DB.DenseFormatDF2DBPlus import *
from PAMI.extras.DF2DB.sparseFormatDF2DBPlus import *
from PAMI.extras.DF2DB.DenseFormatDFPlus import *
from PAMI.extras.DF2DB.SparseFormatDFPlus import *
import sys


Expand Down Expand Up @@ -72,9 +72,9 @@ def __init__(self, inputDF, thresholdConditionDF, DFtype='sparse') -> None:
self.thresholdConditionDF = thresholdConditionDF
self.DFtype = DFtype.lower()
if DFtype == 'sparse':
self.DF2DB = sparseFormatDF2DBPlus(self.inputDF, self.thresholdConditionDF)
self.DF2DB = SparseFormatDFPlus(self.inputDF, self.thresholdConditionDF)
elif DFtype == 'dense':
self.DF2DB = DenseFormatDF2DBPlus(self.inputDF, self.thresholdConditionDF)
self.DF2DB = DenseFormatDFPlus(self.inputDF, self.thresholdConditionDF)
else:
raise Exception('DF type should be sparse or dense')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# DenseFormatDF2DB in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
# DenseFormatDF in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
# from PAMI.extras.DF2DB import DenseFormatDF2DB as db
# from PAMI.extras.DF2DB import DenseFormatDF as db
#
# obj = db.DenseFormatDF2DB(idf, ">=", 16)
# obj = db.DenseFormatDF(idf, ">=", 16)
#
# obj.save(oFile)
#
Expand Down Expand Up @@ -49,7 +49,7 @@
}


class DenseFormatDF2DB:
class DenseFormatDF:
"""
:Description: This class create Data Base from DataFrame.
Expand All @@ -65,9 +65,9 @@ class DenseFormatDF2DB:
--------------------------------------------------------
.. code-block:: python
from PAMI.extras.DF2DB import DenseFormatDF2DB as db
from PAMI.extras.DF2DB import DenseFormatDF as db
obj = db.DenseFormatDF2DB(iDdf, ">=", 16 )
obj = db.DenseFormatDF(iDdf, ">=", 16 )
obj.convert2TransactionalDatabase("outputFileName") # To create transactional database
Expand Down Expand Up @@ -266,7 +266,7 @@ def getFileName(self) -> str:
# Dataframes do not run from a terminal

# if __name__ == '__main__':
# obj = DenseFormatDF2DB(sys.argv[1], sys.argv[2], sys.argv[3])
# obj = DenseFormatDF(sys.argv[1], sys.argv[2], sys.argv[3])
# obj.convert2TransactionalDatabase(sys.argv[4])
# transactionalDB = obj.getFileName()
# print(transactionalDB)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# sparseFormatDF2DB in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
# SparseFormatDF in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
# from PAMI.extras.DF2DB import sparseFormatDF2DB as db
# from PAMI.extras.DF2DB import SparseFormatDF as db
#
# obj = db.sparseFormatDF2DB(idf, ">=", 16)
# obj = db.SparseFormatDF(idf, ">=", 16)
#
# obj.save(oFile)
#
Expand Down Expand Up @@ -38,7 +38,7 @@
import pandas as pd
import sys

class sparseFormatDF2DB:
class SparseFormatDF:
"""
:Description: This class create Data Base from DataFrame.
Expand All @@ -55,9 +55,9 @@ class sparseFormatDF2DB:
--------------------------------------------------------
.. code-block:: python
from PAMI.extras.DF2DB import sparseFormatDF2DB as db
from PAMI.extras.DF2DB import SparseFormatDF as db
obj = db.sparseFormatDF2DB(iDdf, ">=", 16)
obj = db.SparseFormatDF(iDdf, ">=", 16)
obj.save(oFile)
Expand Down Expand Up @@ -155,6 +155,6 @@ def getFileName(self) -> str:

if __name__ == '__main__':

obj = sparseFormatDF2DB(sys.argv[1], sys.argv[2])
obj = SparseFormatDF(sys.argv[1], sys.argv[2])
obj.getFileName(sys.argv[3])

16 changes: 8 additions & 8 deletions PAMI/extras/DF2DB/denseDF2DBPlus.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# DenseFormatDF2DBPlus in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
# DenseFormatDFPlus in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
# from PAMI.extras.DF2DB import DenseFormatDF2DBPlus as db
# from PAMI.extras.DF2DB import DenseFormatDFPlus as db
#
# obj = db.DenseFormatDF2DBPlus(idf, ">=", 16)
# obj = db.DenseFormatDFPlus(idf, ">=", 16)
#
# obj.save(oFile)
#
Expand Down Expand Up @@ -39,7 +39,7 @@
import pandas as pd
import sys

class DenseFormatDF2DBPlus:
class DenseFormatDFPlus:
"""
:Description: This class create Data Base from DataFrame.
Expand All @@ -53,9 +53,9 @@ class DenseFormatDF2DBPlus:
--------------------------------------------------------
.. code-block:: python
from PAMI.extras.DF2DB import DenseFormatDF2DBPlus as db
from PAMI.extras.DF2DB import DenseFormatDFPlus as db
obj = db.DenseFormatDF2DBPlus(iDdf, ">=", 16)
obj = db.DenseFormatDFPlus(iDdf, ">=", 16)
obj.save(oFile)
Expand Down Expand Up @@ -171,6 +171,6 @@ def getFileName(self) -> str:
return self.outputFile

if __name__ == '__main__':
a = DenseFormatDF2DBPlus(sys.argv[1], sys.argv[3])
a.DenseFormatDF2DBPlus()
a = DenseFormatDFPlus(sys.argv[1], sys.argv[3])
a.DenseFormatDFPlus()

14 changes: 7 additions & 7 deletions PAMI/extras/DF2DB/denseDF2DB_dump.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# DenseFormatDF2DB_dump in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
# DenseFormatDF_dump in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
# from PAMI.extras.DF2DB import DenseFormatDF2DB_dump as db
# from PAMI.extras.DF2DB import DenseFormatDF_dump as db
#
# obj = db.DenseFormatDF2DB_dump(idf, ">=", 16)
# obj = db.DenseFormatDF_dump(idf, ">=", 16)
#
# obj.save(oFile)
#
Expand Down Expand Up @@ -38,7 +38,7 @@

import pandas as pd
import sys
class DenseFormatDF2DB():
class DenseFormatDF():
"""
:Description: This class create Data Base from DataFrame.
Expand All @@ -53,9 +53,9 @@ class DenseFormatDF2DB():
--------------------------------------------------------
.. code-block:: python
from PAMI.extras.DF2DB import DenseFormatDF2DB_dump as db
from PAMI.extras.DF2DB import DenseFormatDF_dump as db
obj = db.DenseFormatDF2DB_dump(iDdf, ">=", 16)
obj = db.DenseFormatDF_dump(iDdf, ">=", 16)
obj.save(oFile)
Expand Down Expand Up @@ -303,6 +303,6 @@ def getFileName(self) -> str:
if __name__ == '__main__':


obj = DenseFormatDF2DB(sys.argv[1], sys.argv[2])
obj = DenseFormatDF(sys.argv[1], sys.argv[2])
obj.getFileName(sys.argv[3])

14 changes: 7 additions & 7 deletions PAMI/extras/DF2DB/sparseDF2DBPlus.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# sparseFormatDF2DBPlus in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
# SparseFormatDFPlus in this code the dense dataframe is converting databases into different transactional, temporal, utility types.
#
# **Importing this algorithm into a python program**
# --------------------------------------------------------
#
# from PAMI.extras.DF2DB import sparseFormatDF2DBPlus as db
# from PAMI.extras.DF2DB import SparseFormatDFPlus as db
#
# obj = db.sparseFormatDF2DBPlus(idf, ">=", 16)
# obj = db.SparseFormatDFPlus(idf, ">=", 16)
#
# obj.save(oFile)
#
Expand Down Expand Up @@ -38,7 +38,7 @@
import pandas as pd
import sys

class sparseFormatDF2DBPlus:
class SparseFormatDFPlus:
"""
:Description: This class create Data Base from DataFrame.
Expand All @@ -52,9 +52,9 @@ class sparseFormatDF2DBPlus:
--------------------------------------------------------
.. code-block:: python
from PAMI.extras.DF2DB import sparseFormatDF2DBPlus as db
from PAMI.extras.DF2DB import SparseFormatDFPlus as db
obj = db.sparseFormatDF2DBPlus(iDdf, ">=", 16)
obj = db.SparseFormatDFPlus(iDdf, ">=", 16)
obj.save(oFile)
Expand Down Expand Up @@ -151,5 +151,5 @@ def getFileName(self) -> str:


if __name__ == '__main__':
obj = sparseFormatDF2DBPlus(sys.argv[1], sys.argv[2])
obj = SparseFormatDFPlus(sys.argv[1], sys.argv[2])
obj.getFileName(sys.argv[3])
38 changes: 19 additions & 19 deletions PAMI/extras/dbStats/TemporalDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

import sys
import statistics
import pandas as pd
Expand Down Expand Up @@ -100,8 +101,7 @@ class TemporalDatabase:
"""


def __init__(self, inputFile: Union[str, pd.DataFrame], sep: str='\t') -> None:
def __init__(self, inputFile: Union[str, pd.DataFrame], sep: str = '\t') -> None:
"""
:param inputFile: input file name or path
:type inputFile: str
Expand Down Expand Up @@ -167,7 +167,7 @@ def readDatabase(self) -> None:
for ts in timeStampList:
self.periodList.append(int(ts) - preTimeStamp)
preTimeStamp = ts

for x, y in self.database.items():
for i in y:
if i not in self.periods:
Expand Down Expand Up @@ -277,31 +277,30 @@ def getSortedListOfItemFrequencies(self) -> Dict[str, int]:
itemFrequencies[item] = itemFrequencies.get(item, 0)
itemFrequencies[item] += 1
return {k: v for k, v in sorted(itemFrequencies.items(), key=lambda x: x[1], reverse=True)}

def getFrequenciesInRange(self) -> Dict[int, int]:
fre = self.getSortedListOfItemFrequencies()
rangeFrequencies = {}
maximum = max([i for i in fre.values()])
values = [int(i*maximum/6) for i in range(1,6)]
#print(maximum)
values = [int(i * maximum / 6) for i in range(1, 6)]
# print(maximum)
va = len({key: val for key, val in fre.items() if val > 0 and val < values[0]})
rangeFrequencies[va] = values[0]
for i in range(1,len(values)):

va = len({key: val for key, val in fre.items() if val < values[i] and val > values[i-1]})
for i in range(1, len(values)):
va = len({key: val for key, val in fre.items() if val < values[i] and val > values[i - 1]})
rangeFrequencies[va] = values[i]
return rangeFrequencies

def getPeriodsInRange(self) -> Dict[int, int]:
fre = {k: v for k, v in sorted(self.periods.items(), key=lambda x: x[1])}
rangePeriods = {}
maximum = max([i for i in fre.values()])
values = [int(i*maximum/6) for i in range(1,6)]
#print(maximum)
values = [int(i * maximum / 6) for i in range(1, 6)]
# print(maximum)
va = len({key: val for key, val in fre.items() if val > 0 and val < values[0]})
rangePeriods[va] = values[0]
for i in range(1,len(values)):
va = len({key: val for key, val in fre.items() if val < values[i] and val > values[i-1]})
for i in range(1, len(values)):
va = len({key: val for key, val in fre.items() if val < values[i] and val > values[i - 1]})
rangePeriods[va] = values[i]
return rangePeriods

Expand Down Expand Up @@ -349,21 +348,21 @@ def getMaximumInterArrivalPeriod(self) -> int:
:return: maximum inter arrival period
"""
return max(self.periodList)

def getMinimumPeriodOfItem(self) -> int:
"""
get the minimum period of the item
:return: minimum period
"""
return min([i for i in self.periods.values()])

def getAveragePeriodOfItem(self) -> float:
"""
get the average period of the item
:return: average period
"""
return sum([i for i in self.periods.values()]) / len(self.periods)

def getMaximumPeriodOfItem(self) -> int:
"""
get the maximum period of the item
Expand All @@ -385,7 +384,7 @@ def getNumberOfTransactionsPerTimestamp(self) -> Dict[int, int]:
"""
maxTS = max(list(self.timeStampCount.keys()))
return {ts: self.timeStampCount.get(ts, 0) for ts in range(1, maxTS + 1)}

def printStats(self) -> None:
print(f'Database size : {self.getDatabaseSize()}')
print(f'Number of items : {self.getTotalNumberOfItems()}')
Expand All @@ -401,14 +400,15 @@ def printStats(self) -> None:
print(f'Standard Deviation Transaction Size : {self.getStandardDeviationTransactionLength()}')
print(f'Variance : {self.getVarianceTransactionLength()}')
print(f'Sparsity : {self.getSparsity()}')

def plotGraphs(self) -> None:
itemFrequencies = self.getFrequenciesInRange()
transactionLength = self.getTransanctionalLengthDistribution()
plt.plotLineGraphFromDictionary(itemFrequencies, 100, 0, 'Frequency', 'no of items', 'frequency')
plt.plotLineGraphFromDictionary(transactionLength, 100, 0, 'transaction length', 'transaction length',
'frequency')


if __name__ == '__main__':
data = {'tid': [1, 2, 3, 4, 5, 6, 7],

Expand Down
4 changes: 2 additions & 2 deletions docs/dataFrameCoversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Key concepts in each link were briefly mentioned to save your valuable time. Cli
Default separator used in PAMI is tab space. However, users can override the separator with their choice.

1. [Converting Dataframes to Databases](df2db.html)
1. [Dense dataframe to database](DenseFormatDF2DB.html)
1. [Sparse dataframe to database](sparseFormatDF2DB.html)
1. [Dense dataframe to database](DenseFormatDF.html)
1. [Sparse dataframe to database](SparseFormatDF.html)
1. [Spatiotemporal dataframe to databases](stDF2DB.html)

Loading

0 comments on commit 5d8035a

Please sign in to comment.