Package: tpcs
Time Pattern Cohesion ScoreIntroductionhttps://pypi.org/project/tpcs/0.0.4/TPCS is a metric to assess how well time-dependent patterns within a time series signal remain connected over time, with an emphasis on recency.We calculate TPCS using 4 main features :Consistency: shows if data collection is consistent with respect to  start and end time of data crawling  , (from  2020-09 to current time)Intra Consistency: shows if data collection was consistent with respect to signal’s own start and end time.Contiguity: shows how contiguous data is. 5 is fully contiguous which means all existed values are sequentialRecent Contiguity: shows how contiguous recent data is.Table of ContentsIntroductionInstallationUsageFeaturesDependenciesDocumentationExamplesLicenseInstallation & Importpipinstalltpcsimportpandasaspdfromtime_pattern_cohesion_scoreimportTPCSEND_OF_TIME=pd.to_datetime("2021-05-01")MAX_LEN_MONTHS=13list_of_timestamps=["2020-05-01","2020-06-01","2020-07-01","2020-08-01","2020-09-01","2020-10-01","2020-11-01","2020-12-01","2021-01-01","2021-03-01","2021-04-01","2021-05-01"]#notice that "2021-02-01" is missinglist_of_timestamps=[pd.to_datetime(e)foreinlist_of_timestamps]tpcs=TPCS(list_of_timestamps,MAX_LEN_MONTHS,END_OF_TIME)print(tpcs.calculate_TPCS())# Output:# Contiguity : 4.49# Recent_contiguity: 2.88# cconsistency : 3.46# Intra consistency : 3.75# TPCS (weighted avg of all) : 3.64sHow does it work?###How TPC score is calculated?We are first extracting relevant attributes from signals with the help of sequentiality package.  These attributes are:total sample size (n_of_samples)Longest Consecutive Subsequence of months  (LCS_m)Longest Consecutive Subsequence of months with 1 gap month (LCS_m_1g)Longest Consecutive Subsequence of months with 2 gap month (LCS_m_1g)Longest Consecutive Subsequence of months from last timestamp (LCS_m_from_last)Longest Consecutive Subsequence of months from last timestamp  with 1 gap month (LCS_m_from_last_1g)Longest Consecutive Subsequence of months from last timestamp  with 2 gap month  (LCS_m_from_last_2g)Longest Consecutive Subsequence of months from end time (LCS_m_from_end)Longest Consecutive Subsequence of months from end time  with 1 gap month  (LCS_m_from_end_1g)And then these attributes are group together into 4 features:Consistency: shows if data collection is consistent with respect to  start and end time of data crawling  , (from  2020-09 to current time)Intra Consistency: shows if data collection was consistent with respect to signal’s own start and end time.Contiguity: shows how contiguous data is. 5 is fully contiguous which means all existed values are sequentialRecent Contiguity: shows how contiguous recent data is.Then These features are turned into scores by calculating their ratio to max signal length and normalizing them between 0 and 5.And we take weighted avg of these normalized scores to calculate TPC.Features & UsageTPC score designed as a data quality assesment for time signals. It is really easy to use.#Lets assume we have signal of interest. TPC requires dates of this signal as input.importdatetimedate_list=['2023-01-01','2023-02-01','2023-03-01','2023-04-01','2023-05-01','2023-06-01','2023-07-01','2023-08-01','2023-09-01','2023-11-01','2023-12-01','2024-01-01']# there are 12 months in this list. '2023-10-01'  is missing.date_list=[datetime.datetime.strptime(date_str,"%Y-%m-%d").date()fordate_strinspecific_dates]weights={"contiguity_score":0.5,"recent_contiguity_score":3,"consistency_score":0.8,"intra_consistency_score":1}MAX_LEN_MONTHS=13END_OF_TIME='2024-01-01'tpcs=TPCS(date_list,MAX_LEN_MONTHS,END_OF_TIME=END_OF_TIME,debug=False,return_details=True)TPC_score,tpcs_details=tpcs.calculate_TPCS(weights=weights,printing=False)Documentationhttps://github.com/karaposu/time-pattern-cohesion-scoreLicenseMIT LicenseCopyright (c) 2024 Enes KuzucuPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.