Ejemplo n.º 1
0
 def test_compress_and_decompress_zlib(self) -> None:
     byte_instance = b'a' * 26
     byte_compressed = utils.compress_to_zlib(byte_instance)
     self.assertLess(sys.getsizeof(byte_compressed),
                     sys.getsizeof(byte_instance))
     self.assertEqual(utils.decompress_from_zlib(byte_compressed),
                      byte_instance)
Ejemplo n.º 2
0
def save_classifier_data(exp_id, job_id, classifier_data_proto):
    """Store classifier model data in a file.

    Args:
        exp_id: str. The id of the exploration.
        job_id: str. The id of the classifier training job model.
        classifier_data_proto: Object. Protobuf object of the classifier data
            to be stored.
    """
    filepath = '%s-classifier-data.pb.xz' % (job_id)
    file_system_class = get_entity_file_system_class()
    fs = fs_domain.AbstractFileSystem(
        file_system_class(feconf.ENTITY_TYPE_EXPLORATION, exp_id))
    content = utils.compress_to_zlib(classifier_data_proto.SerializeToString())
    fs.commit(filepath, content, mimetype='application/octet-stream')
Ejemplo n.º 3
0
def save_classifier_data(exp_id: str, job_id: str,
                         classifier_data_proto: object) -> None:
    """Store classifier model data in a file.

    Args:
        exp_id: str. The id of the exploration.
        job_id: str. The id of the classifier training job model.
        classifier_data_proto: Object. Protobuf object of the classifier data
            to be stored.
    """
    filepath = '%s-classifier-data.pb.xz' % (job_id)
    fs = GcsFileSystem(feconf.ENTITY_TYPE_EXPLORATION, exp_id)
    content = utils.compress_to_zlib(
        # Here, classifier_data_proto is of general object type and general
        # objects do not contain any extra methods and properties. Thus to
        # avoid MyPy error, we added an [attr-defined] ignore statement.
        classifier_data_proto.SerializeToString()
    )  # type: ignore[attr-defined]
    fs.commit(filepath, content, mimetype='application/octet-stream')