|
| 1 | +from __future__ import annotations |
| 2 | +from datetime import datetime |
| 3 | +from typing import Dict, Any |
| 4 | + |
| 5 | +from ravendb.documents.indexes.definitions import ( |
| 6 | + IndexState, |
| 7 | + IndexPriority, |
| 8 | + IndexLockMode, |
| 9 | + IndexType, |
| 10 | + IndexSourceType, |
| 11 | + IndexRunningStatus, |
| 12 | +) |
| 13 | +from ravendb.tools.utils import Utils |
| 14 | + |
| 15 | + |
| 16 | +class IndexStats: |
| 17 | + def __init__( |
| 18 | + self, |
| 19 | + name: str = None, |
| 20 | + map_attempts: int = None, |
| 21 | + map_successes: int = None, |
| 22 | + map_errors: int = None, |
| 23 | + map_reference_attempts: int = None, |
| 24 | + map_reference_successes: int = None, |
| 25 | + map_reference_errors: int = None, |
| 26 | + reduce_attempts: int = None, |
| 27 | + reduce_successes: int = None, |
| 28 | + reduce_errors: int = None, |
| 29 | + reduce_output_collection: str = None, |
| 30 | + reduce_output_reference_pattern: str = None, |
| 31 | + pattern_references_collection_name: str = None, |
| 32 | + mapped_per_second_rate: float = None, |
| 33 | + reduced_per_second_rate: float = None, |
| 34 | + max_number_of_outputs_per_document: int = None, |
| 35 | + collections: Dict[str, CollectionStats] = None, |
| 36 | + last_querying_time: datetime = None, |
| 37 | + state: IndexState = None, |
| 38 | + priority: IndexPriority = None, |
| 39 | + created_timestamp: datetime = None, |
| 40 | + last_indexing_time: datetime = None, |
| 41 | + stale: bool = None, |
| 42 | + lock_mode: IndexLockMode = None, |
| 43 | + type: IndexType = None, |
| 44 | + status: IndexRunningStatus = None, |
| 45 | + entries_count: int = None, |
| 46 | + errors_count: int = None, |
| 47 | + source_type: IndexSourceType = None, |
| 48 | + is_test_index: bool = None, |
| 49 | + ): |
| 50 | + self.name = name |
| 51 | + self.map_attempts = map_attempts |
| 52 | + self.map_successes = map_successes |
| 53 | + self.map_errors = map_errors |
| 54 | + self.map_reference_attempts = map_reference_attempts |
| 55 | + self.map_reference_successes = map_reference_successes |
| 56 | + self.map_reference_errors = map_reference_errors |
| 57 | + self.reduce_attempts = reduce_attempts |
| 58 | + self.reduce_successes = reduce_successes |
| 59 | + self.reduce_errors = reduce_errors |
| 60 | + self.reduce_output_collection = reduce_output_collection |
| 61 | + self.reduce_output_reference_pattern = reduce_output_reference_pattern |
| 62 | + self.pattern_references_collection_name = pattern_references_collection_name |
| 63 | + self.mapped_per_second_rate = mapped_per_second_rate |
| 64 | + self.reduced_per_second_rate = reduced_per_second_rate |
| 65 | + self.max_number_of_outputs_per_document = max_number_of_outputs_per_document |
| 66 | + self.collections = collections |
| 67 | + self.last_querying_time = last_querying_time |
| 68 | + self.state = state |
| 69 | + self.priority = priority |
| 70 | + self.created_timestamp = created_timestamp |
| 71 | + self.last_indexing_time = last_indexing_time |
| 72 | + self.stale = stale |
| 73 | + self.lock_mode = lock_mode |
| 74 | + self.type = type |
| 75 | + self.status = status |
| 76 | + self.entries_count = entries_count |
| 77 | + self.errors_count = errors_count |
| 78 | + self.source_type = source_type |
| 79 | + self.is_test_index = is_test_index |
| 80 | + |
| 81 | + class CollectionStats: |
| 82 | + def __init__( |
| 83 | + self, |
| 84 | + last_processed_document_etag: int = None, |
| 85 | + last_processed_tombstone_etag: int = None, |
| 86 | + document_lag: int = None, |
| 87 | + tombstone_lag: int = None, |
| 88 | + ): |
| 89 | + self.last_processed_document_etag = last_processed_document_etag |
| 90 | + self.last_processed_tombstone_etag = last_processed_tombstone_etag |
| 91 | + self.document_lag = document_lag |
| 92 | + self.tombstone_lag = tombstone_lag |
| 93 | + |
| 94 | + @classmethod |
| 95 | + def from_json(cls, json_dict: Dict[str, Any]) -> "IndexStats.CollectionStats": |
| 96 | + return cls( |
| 97 | + json_dict["LastProcessedDocumentEtag"], |
| 98 | + json_dict["LastProcessedTombstoneEtag"], |
| 99 | + json_dict["DocumentLag"], |
| 100 | + json_dict["TombstoneLag"], |
| 101 | + ) |
| 102 | + |
| 103 | + @classmethod |
| 104 | + def from_json(cls, json_dict: Dict[str, Any]) -> IndexStats: |
| 105 | + return cls( |
| 106 | + json_dict["Name"], |
| 107 | + json_dict["MapAttempts"], |
| 108 | + json_dict["MapSuccesses"], |
| 109 | + json_dict["MapErrors"], |
| 110 | + json_dict["MapReferenceAttempts"], |
| 111 | + json_dict["MapReferenceSuccesses"], |
| 112 | + json_dict["MapReferenceErrors"], |
| 113 | + json_dict["ReduceAttempts"], |
| 114 | + json_dict["ReduceSuccesses"], |
| 115 | + json_dict["ReduceErrors"], |
| 116 | + json_dict["ReduceOutputCollection"], |
| 117 | + json_dict["ReduceOutputReferencePattern"], |
| 118 | + json_dict["PatternReferencesCollectionName"], |
| 119 | + json_dict["MappedPerSecondRate"], |
| 120 | + json_dict["ReducedPerSecondRate"], |
| 121 | + json_dict["MaxNumberOfOutputsPerDocument"], |
| 122 | + {key: cls.CollectionStats.from_json(value) for key, value in json_dict["Collections"].items()}, |
| 123 | + Utils.string_to_datetime(json_dict["LastQueryingTime"]), |
| 124 | + IndexState(json_dict["State"]), |
| 125 | + IndexPriority(json_dict["Priority"]), |
| 126 | + Utils.string_to_datetime(json_dict["CreatedTimestamp"]), |
| 127 | + Utils.string_to_datetime(json_dict["LastIndexingTime"]), |
| 128 | + json_dict["IsStale"], |
| 129 | + IndexLockMode(json_dict["LockMode"]), |
| 130 | + IndexType(json_dict["Type"]), |
| 131 | + IndexRunningStatus(json_dict["Status"]), |
| 132 | + json_dict["EntriesCount"], |
| 133 | + json_dict["ErrorsCount"], |
| 134 | + IndexSourceType(json_dict["SourceType"]), |
| 135 | + json_dict.get("IsTestIndex", None), |
| 136 | + ) |
0 commit comments