Package: datastories
DataStoryPatternLibrabryData Story Patterns Library is a repository with pattern analysis designated for Linked Open Statistical Data. Story Patterns were retrieved from literture reserach udenr general subject of "data journalism".InstallationpipinstalldatastoriesRequirements will be automatically installed with package###Import/Usageimportdatastories.analyticalaspatternspatterns.DataStoryPattern(sparqlendpointurl,jsonmetadata)Object created allow to query SPARQL endpoint based on JSON meatadat provided.JSON Template{"cube_key":{"title":"title of cube","dataset_structure":"URI for cube structure","dimensions":{"dimension_key":{"dimension_title":"Title of diemnsion","dimension_url":"URI for dimension","dimension_prefix":"URI for dimension's values"},"dimension_key":{"dimension_title":"Title of diemnsion","dimension_url":"URI for dimension","dimension_prefix":"URI for dimension's values"}},"hierarchical_dimensions":{"dimension_key":{"dimension_title":"Title of diemnsion","dimension_url":"URI for dimension","dimension_prefix":"URI for dimension's values","dimension_levels":{"level_key":"integer(granularity level)","level_key":"integer(granularity level)"}}},"measures":{"measure_key":{"measure_title":"Title of measure","measure_url":"URI for measure"}}}}Patterns DescriptionMeasurement and CountingLeague TableInternal ComprisonProfile OutliersDissect FactorsHighlight ContrastStart Big Drill DownStart Small Zoom OutAnalysis By CategoryExplore IntersectionNarrating Change Over TimeMCountingMeasurement and Counting
Arithemtical operators applied to whole dataset - basic information regarding dataAttributesdefMCounting(self,cube="",dims=[],meas=[],hierdims=[],count_type="raw",df=pd.DataFrame())ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationcount_typeStringType of Count to performdfDataFrameDataFrame object, if data is already retrieved from endpointOutputBased on count_type valueCount_typeDescriptionrawdata without any analysis performedsumsum across all numeric columnsmeanmean across all numeric columnsminminimum values from all numeric columnsmaxmaximum values from all numeric columnscountamount of recordsLTableLeagueTable - sorting and extraction specific amount of recordsAttributesdefLTable(self,cube=[],dims=[],meas=[],hierdims=[],columns_to_order="",order_type="asc",number_of_records=20,df=pd.DataFrame())ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationcolumns_to_orderlist[String]Set of columns to order byorder_typeStringType of order (asc/desc)number_of_recordsIntegerAmount of records to retrievedfDataFrameDataFrame object, if data is already retrieved from endpointOutputBased on sort_type valueSort_typeDescriptionascascending order based on columns provided incolumns_to_orderdescdescending order based on columns provided incolumns_to_orderInternalComparisonInternalComparison - comparison of numeric values related to textual values within one columnAttributesdefInternalComparison(self,cube="",dims=[],meas=[],hierdims=[],df=pd.DataFrame(),dim_to_compare="",meas_to_compare="",comp_type="")ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationdfDataFrameDataFrame object, if data is already retrieved from endpointdim_to_compareStringDimension, which values will be investigatedmeas_to_compareStringMeasure, which numeric values related todim_to_comparewill be processedcomp_typeStringType of comparison to performOutputIndependent fromcomp_typeselected, output data will have additional column with numerical columnmeas_to_compareprocessed in specific way.Available types of comparisoncomp_typeComp_typeDescriptiondiffmaxdifference with max value related to specific textual valuediffmeandifference with arithmetic mean related to specific textual valuesdiffmindifference with minimum value related to specific textual valueProfileOutliersProfileOutliers - detection of unusual values within data (anomalies)AttributesdefProfileOutliers(self,cube=[],dims=[],meas=[],hierdims=[],df=pd.DataFrame(),displayType="outliers_only")ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationdfDataFrameDataFrame object, if data is already retrieved from endpointdisplay_typeStringWhat information display are bound to display (with/without anomalies)OutputPattern analysis usingpython scipylibrary will perform quick exploration in serach of unusual values within data.Based ondisplay_typeparameter data will be displayed with/without ddetected unusual values.Available types of displayingdisplay_typedisplay_typeDescriptionoutliers_onlyreturns rows from dataset where unusual values were detectedwithout_outliersreturns dataset with excluded rows where unusual values were detectedDissectFactorsDissectFactors - decomposition of data based on values in dim_to_dissectAttributesdefDissectFactors(self,cube="",dims=[],meas=[],hierdims=[],df=pd.DataFrame(),dim_to_dissect="")ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationdfDataFrameDataFrame object, if data is already retrieved from endpointdim_to_dissectStringBased on which dimension data should be decomposedOutputAs an output, data will be decomposed in a form of a dictionary, where each subset have values only related to specific value.
Dictionary of subdataset will be constructed as a series of paiers where key per each susbet will values fromdim_to_dissectand this key value will be data, where yhis key value was occurring.HighlightContrastHighlightContrast - partial difference within values related to one textual columnAttributesdefHighlightContrast(self,cube="",dims=[],meas=[],hierdims=[],df=pd.DataFrame(),dim_to_contrast="",contrast_type="",meas_to_contrast="")ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationdfDataFrameDataFrame object, if data is already retrieved from endpointdim_to_contrastStringTextual column, from which values will be contrastedmeas_to_contrastStringNumerical column, which values are contrastedcontrast_typeStringType of contrast to presentOutputIndependent fromcontrast_typeselected, output data will have additional column with numerical columnmeas_to_contrastprocessed in specific way.Available types of comparisoncontrast_typeContrast_typeDescriptionpartofwholedifference with max value related to specific textual valuepartofmaxdifference with arithmetic mean related to specific textual valuespartofmindifference with minimum value related to specific textual valueStartBigDrillDownStartBigDrillDown - data retrieval from multiple hierachical levels.This pattern can be only applied to data not stored already in DataFrameAttributesdefStartBigDrillDown(self,cube="",dims=[],meas=[],hierdim_drill_down=[])ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdim_drill_downdict{hierdim:list[str]}Hierarchical dimension with list of hierarchy levels to inspectOutputAs an output, data will be retrieved in a form of a dictionary, where each dataset will be retrieved from different hierachy level. List will be provided inhierdim_drill_down. Hierachy levels provided by in parameter will automatically sorted in order from most general to most detailed level based on metadata provided.StartSmallZoomOutStartSmallZoomOut - data retrieval from multiple hierachical levels.This pattern can be only applied to data not stored already in DataFrameAttributesdefStartSmallZoomOut(self,cube="",dims=[],meas=[],hierdim_zoom_out=[])ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdim_zoom_outdict{hierdim:list[str]}Hierarchical dimension with list of hierarchy levels to inspectOutputAs an output, data will be retrieved in a form of a dictionary, where each dataset will be retrieved from different hierachy level. List will be provided inhierdim_zoom_out. Hierachy levels provided by in parameter will automatically sorted in order from most detaile to most general level based on metadata provided.AnalysisByCategoryAnalysisByCategory - ecomposition of data based on values in dim_for_category with analysis performed on each susbetAttributesdefAnalysisByCategory(self,cube="",dims=[],meas=[],hierdims=[],df=pd.DataFrame(),dim_for_category="",meas_to_analyse="",analysis_type="min"):ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationdfDataFrameDataFrame object, if data is already retrieved from endpointdim_for_categoryStringDimension, based on which input data will be categorisedmeas_to_analyseStringMeasure, which will be analysedanalysis_typeStringType of analysis to performOutputAs an output, data will be decomposed in a form of a dictionary, where each subset have values only related to specific value. Such subset will get analysed based onanalysis_typeparameterAvailable types of analysisanalysis_typeAnalysis_typeDescriptionminMinimum per each categorymaxMaximum per each categorymeanArithmetical mean per each categorysumTotal value from each categoryExploreIntersectionAttributesdefExploreIntersection(self,dim_to_explore=""):ParameterTypeDescriptiondim_to_exploreStringDimension, which existence within enpoint is going to be investigatedOutputPattern will return series of datasets, where each will represent occurence ofdim_to_explorein one cubeNarratingChangeOverTimeAttributesdefNarrChangeOT(self,cube="",dims=[],meas=[],hierdims=[],df=pd.DataFrame(),meas_to_narrate="",narr_type="")ParameterTypeDescriptioncubeStringCube, which dimensions and measures will be investigateddimslist[String]List of dimensions (from cube) to take into investigationmeaslist[String]List of measures (from cube) to take into investigationhierdimsdict{hierdim:{"selected_level":[value]}}Hierarchical Dimesion with selected hierarchy level to take into investigationdfDataFrameDataFrame object, if data is already retrieved from endpointmeas_to_narrateStringSet of 2 measures, which change will be narratednarr_typeStringType of narration to performOutputIndependent fromnarr_typeselected, output data will have additional column with numerical values processed in specific way.Available types of analysisnarr_typeNarr_typeDescriptionpercchangePercentage change between first nad second propertydiffchangeQuantitive change between first and second property