+
   }'.S~c                   sD   R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RIt^ RIt^ RI	t	^ RI
t
R R lt]! 4       t ! R R	4      t]R
8X  EdS   ]! ]P                  ]P                   ]P"                  R7      t]P'                  4        ]P(                  '       d   ]P+                  ]P,                  R7       ]P/                  ]P0                  4       ]P2                  '       d   ]P5                  4        ]P6                  '       d   ]P9                  4        ]P:                  '       d   ]P=                  4        ]P>                  '       d   ]PA                  4        ]PB                  '       d   ]PE                  4        ]PF                  '       d   ]PI                  4        R# R# R# )ze
Utility to inspec the user database of Typing Booster and print
some information about the contents
)List)Tuple)DictAnyNc                s$    V ^8  d   QhR\         /# )   returnr   )formats   "6/usr/share/ibus-typing-booster/engine/tabstatistics.py__annotate__r	   #   s     e eC e    c            
     s   \         P                  ! RR7      p V P                  RRRRRRR	7       V P                  R
RR\        RRRR7       V P                  RRR\        R\	        R4      RR7       V P                  RRRRRRR	7       V P                  RRRRRRR	7       V P                  RR R!RRR"R	7       V P                  R#R$R%\        RR&R'R7       V P                  R(R)RRR*R	7       V P                  R+R,RRR-R	7       V P                  R.R/RRR0R	7       V P                  R1R2R3RRR4R	7       V P                  R5R6R7RRR8R	7       V P                  4       # )9z#
Parse the command line arguments.
z7Tool for inspecting the user database of Typing Booster)Zdescriptionz-vz	--verboseverboseZ
store_trueFz4Print more verbose information. default: %(default)s)destactiondefaulthelpz-fz--filefileZstorez*~/.local/share/ibus-typing-booster/user.dbzAFull path of the database file to inspect, default: "%(default)s")r   Ztyper   r   r   z-mz
--max-rowsmax_rowsP  zFMaximum number of rows to keep in the database. default: "%(default)s"z-rz--rowsrowsz4Print all rows of the database, default: %(default)sz-sz--sortsort	user_freqzPSort order when printing all rows. Can be "user_freq|time". default: %(default)sz-tz--total-rows
total_rowsz@Print total number of rows in the database. default: %(default)sz-pz--periodperiodnonezPrint keystrokes saved by period. Period can be "none|second(s)|minute(s)|hour(s)|day(s)|week(s)|month(s)|year(s)|total(s)". "none" means do not print saved keystrokes. default: "%(default)s"z--time_newesttime_newestz?Show the newest timestamp in the database. default: %(default)sz--time_oldesttime_oldestz?Show the oldest timestamp in the database. default: %(default)sz
--time_nowtime_nowuW   Show the timestamp used for “now” when doing the calculations. default: %(default)sz-uz--user_freq_distributionuser_freq_distributionzShow the distribution of user frequencies, i.e. how many rows are there wich have been used once, how many rows have been  used twice, etc. ... default: %(default)sz-dz--decaydecayu   Show information about which rows would be decayed or deleted. (Just shows information, doesn’t change the database!) default: %(default)s)argparseZArgumentParserZadd_argumentstrint
parse_args)Zparsers    r   r!   r!   #   s    $$MOF
k$  & h<'  ) lE
'  ) h%  ' h%  ' n%  ' j%  ' %  ' %  ' %  ' (%%  ' i%  ' r
   c                   s  a  ] tR t^t o RtRV 3R lR lltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
RV 3R lR lltV 3R lR lt]RV 3R lR ll4       tRV 3R lR lltV 3R lR ltV 3R lR ltRtV tR# ) 
DbContentsz-
Class used to analyse the database contents
c                s0   < V ^8  d   QhRS[ RS[RS[RR/# )r   user_db_filer   r   r   N)r   r    Zboolr   __classdict__   "r   r	   DbContents.__annotate__   s3     ; ;; ; 	; '+	;r
   c                s.   W n         W0n        \        P                  ! 4       V n        \        P
                  P                  V4      V n        \        P                  ! V P                  4      V n
        . V n        V P                  P                  R 4      P                  4       V n        V P                  4        RV n        RV n        V P                  '       dA   V P                  ^ ,          ^,          V n        V P                  R,          ^,          V n        R# R# )zSELECT * FROM phrases;        N)	_max_rows_verbosetime	_time_nowosZpathZ
expanduser_user_db_filesqlite3Zconnect	_database_original_rowsZexecuteZfetchallsort_by_time_ascending_time_oldest_time_newest)selfr#   r   r   s   &&&&r   __init__ZDbContents.__init__   s    
 "WW//= ););<PR"nn445MNWWY##% $ 3 3A 6q 9D $ 3 3B 7 :D r
   c                   < V ^8  d   QhRR/# r   r   N r$   r&   r   r	   r'      s     B- B-T B-r
   c                s*   V P                  4        \        RV P                   24       \        V P                  4      p^ p. pV P                   Fz  pV^,          pWP                  8  dE   V\
        P                  8  d0   V^,          pV P                  '       d   V P                  VRR7       MVP                  V4       V^,          pK|  	  \        RV 24       \        VR R7      pV P                  '       d   V F  pV P                  VRR7       K  	  \        V4      p\        RV 24       \        V P                  R	,          4      p\        R
V 24       ^ p^ pV F  pV^,          pW8  dz   V\
        P                  8  de   V^8X  d0   V^,          pV P                  '       d   V P                  VRR7       M.V^,          pV P                  '       d   V P                  VRR7       V^,          pK  	  \        RV 24       \        RV 24       R# )z;Print information how many rows would be decayed or deletedz)1st pass: Maximum number of rows to keep=z1st pass delete: )prefixz61st pass: Number of rows to delete above maximum size=c                 &    V ^,          V ^ ,          3# i   r:   Zx   &r   <lambda>Z(DbContents.print_decay.<locals>.<lambda>   s     t t,r
   Zkeyz1st pass kept: z1st pass: Number of rows kept=g+?z2nd pass: Index for decay=z2nd pass delete: z2nd pass decay: z"2nd pass: Number of rows to decay=z#2nd pass: Number of rows to delete=N) sort_by_user_freq_time_ascendingprintr*   lenr2   itb_utilZSHORTCUT_USER_FREQr+   
_print_rowZappendsortedr    )	r6   indexZnumber_delete_above_maxZ	rows_keptrowr   Zindex_decayZnumber_of_rows_to_decayZnumber_of_rows_to_deletes	   &        r   print_decayZDbContents.print_decay   s   --/9 " 	#D''("#FH	&&CAI& ; ;;'1,'===OOC0COD  %QJE ' 	F()+ 	,$ 9"	
 === ,=> !I.ug67$..501*;-89"##$ CAI# ; ;;>,1,}}}4GH+q0+}}}4FGQJE  	2()+ 	,3)*, 	-r
   c                r8   r9   r:   r$   r&   r   r	   r'      s     B B$ Br
   c                sH    \        R\        V P                  4       24       R# )zPrint the total number of rowszTotal number of rows=N)rC   rD   r2   r6   r?   r   print_total_rowsZDbContents.print_total_rows   s    %c$*=*=&>%?@Ar
   c                r8   r9   r:   r$   r&   r   r	   r'           2 24 2r
   c                x    \        RV P                   R\        P                  ! V P                  4       24       R# )z*Print the oldest timestamp in the databasezOldest timestamp= N)rC   r4   r,   ctimerK   r?   r   print_time_oldestZDbContents.print_time_oldest   4    !$"3"3!4AD--./1 	2r
   c                r8   r9   r:   r$   r&   r   r	   r'      rM   r
   c                rN   )z*Print the newest timestamp in the databasezNewest timestamp=rO   N)rC   r5   r,   rP   rK   r?   r   print_time_newestZDbContents.print_time_newest   rR   r
   c                r8   r9   r:   r$   r&   r   r	   r'      s     / / /r
   c                rN   )uC   Print the timestamp used for “now” when doing the calculations.zNow timestamp=rO   N)rC   r-   r,   rP   rK   r?   r   print_time_nowZDbContents.print_time_now   s/    t~~.aDNN+,. 	/r
   c                $   < V ^8  d   QhRS[ RR/# )r   r   r   Nr   r$   r&   r   r	   r'      s     Z4 Z4C Z4T Z4r
   c                s   / p/ p/ p/ p/ p/ pR^ R^R^<RRRRRRRRR	RR
V P                   V P                  ,
          /	pVP                  V^ 4      p	V	'       g/   VP                  R4      '       d   VRR pVP                  V^ 4      p	V P                   EF  p
V
^,          pV
^,          p\        V
^,          4      V,          p\        V
^,          4      V,          pV	^ 8  g   KQ  \        V P                   V,
          V	,          4      pVR
8X  d   ^ pW8  g   K  W9   dX   W/;;,          V,          uu&   W?;;,          V,          uu&   W8  d)   W_;;,          V,          uu&   Wo;;,          V,          uu&   MWV&   WV&   W8  d
   WV&   WV&   M^ W_&   ^ Wo&   W?,          '       d-   RW?,          W/,          ,
          ,          W?,          ,          WO&   MRWO&   Wo,          '       d/   RWo,          W_,          ,
          ,          Wo,          ,          W&   EK{  RW&   EK  	  \        VRR7       FW  p\        V RVR RVV,          R RVV,          R RVV,          R RVV,          R RVV,          R RVV,          R R24       KY  	  R# )z$Print the keystrokes saved by periodr   ZsecondZminuteZhouri  ZdayZweekZmonthZyearZtotalZsNg      Y@r(   T)ZreverserO   Z3: 7z6.4z% Z%iQ i:	 i ' i3r)   )	r-   r4   ZgetZendswithr2   rD   r    rG   rC   )r6   r   Zlength_typedZlength_committedZpercent_savedZlength_typed_bZlength_committed_bZpercent_saved_bZperiod_lengths_in_secondsZperiod_length_in_secondsrI   r   Z	timestampZlength_typed_rowZlength_committed_rowZperiod_indexrH   s   &&               r   print_savingsZDbContents.print_savings   s   ')+-*,)+-/,.AabD9M^OT^^d&7&77
%
! $=#@#@#K 'FOOC,@,@CR[F'@'D'DVQ'O$&&CAIAI  #3q6{Y6 $'s1v;#: '!+"DNNY$>BZ#Z[W$#$L'; $3$26FF2(6:NN6/B*8<LL8.<@TT<5E\29M6/B;K<8?S|<;<N8?@.<'55!%5%C'3'A&B C.<= &3
 7:3)77!%7%E'5'C&D E0>? (5
 9<5w 'x ,d;EVHAeAYb!%(+1%e,Q/q"5)#.b#E*1-Q'.q1$U+C03 4 <r
   c                r8   r9   r:   r$   r&   r   r	   r'   W  s     
5 
5d 
5r
   c                s    / pV P                    F,  pV^,          pW19   d   W;;,          ^,          uu&   K(  ^W&   K.  	  \        V4       F  p\        VR RW,           24       K  	  R# )z*Print the distribution of user frequenciesrX   rW   N)r2   rG   rC   )r6   Z
user_freqsrI   r   Zcounts   &    r   print_user_freq_distributionZ'DbContents.print_user_freq_distributionW  sf    %'
&&CAI&%*%()
% ' J'EU1IR
 1234 (r
   c          	      sT   < V ^8  d   QhRS[ S[S[S[S[S[S[S[3,          RS[RR/# )r   rI   r;   r   N)r   r    r   Zfloatr$   r&   r   r	   r'   d  s9      c3S#sEAB(,r
   c                s   \        V V^ ,          R RV^,          R R\        P                  ! R\        P                  ! V^,          4      4       \	        V^,          \        V^,          4      ,
          4      R,           R\        V^,          4       R\        V^,          4       R\        V^,          4       R\        V^,          4       R24       R# )i    rX   rO   z%Y-%m-%d %H:%M:%S:i   i   NN)rC   r,   ZstrftimeZgmtimer   r    Zrepr)ZclsrI   r;   s   &&&r   rF   ZDbContents._print_rowc  s     	Q
!Q
!2DKKA4GHISVCAK'(-.ac!fac!fac!fac!fa! 		r
   c                rU   )r   r   r   NrV   r$   r&   r   r	   r'   r  s     	! 	! 	!t 	!r
   c                s    VR8X  d   V P                  4        MVR8X  d   V P                  4        MR# V P                   F  pV P                  V4       K  	  R# )zPrint all rows of the databaser   r,   N)rB   r3   r2   rF   )r6   r   rI   s   && r   dumpZDbContents.dumpr  sH    ;113V^'')&&COOC  'r
   c                r8   r9   r:   r$   r&   r   r	   r'   }  s     ( ( (r
   c                @    \        V P                  R R7      V n        R# )zSort rows by time ascendingc                 r<   r=   r:   r>   r?   r   r@   Z3DbContents.sort_by_time_ascending.<locals>.<lambda>  s    )*1)*16'r
   rA   NrG   r2   rK   r?   r   r3   Z!DbContents.sort_by_time_ascending}  s    $T%8%8,'(r
   c                r8   r9   r:   r$   r&   r   r	   r'     s     ( ($ (r
   c                r\   )z1Sort rows by user_freq and the by time, ascendingc                 s6    V ^,          V ^,          V ^ ,          3# )i   r:   r>   r?   r   r@   Z=DbContents.sort_by_user_freq_time_ascending.<locals>.<lambda>  s    )*1)*1)*16'r
   rA   Nr]   rK   r?   r   rB   Z+DbContents.sort_by_user_freq_time_ascending  s    $T%8%8,'(r
   )r1   r*   r2   r5   r-   r4   r/   r+   N) r   F)r   )r^   )r   )__name__Z
__module__Z__qualname__Z__firstlineno____doc__r7   rJ   rL   rQ   rS   rT   rY   rZ   ZclassmethodrF   r[   r3   rB   Z__static_attributes__Z__classdictcell__)r%   s   @r   r"   r"      s     ; ;(B- B-HB B2 2
2 2
/ /
Z4 Z4x
5 
5   	! 	!( (( (r
   r"   Z__main__)r#   r   r   )r   )%r`   Ztypingr    r   r   r   r.   r,   r0   r   rE   r!   Z_ARGSr"   r_   r   r   r   Z
dbcontentsrB   r   r[   r   rY   r   r   rZ   r   rQ   r   rS   r   rT   r   rJ   r   rL   r:   r
   r   <module>ra      s;  &
     	    eN 	@( @(D z$)MM%*^^5J //1zzzUZZ(U\\*###//1$$&$$&~~~!!#{{{ ##% % r
   