Это хорошо для объектов для доступа к репозиториям?

Вы можете использовать pd.cut с np.linspace, чтобы указать ячейки. Это кодирует ваш столбец категорически, из которого вы можете затем извлечь коды в следующем порядке:

bins = np.linspace(df.time.min() - 1, df.time.max(), 10)
df['time'] = pd.cut(df.time, bins=bins, right=True).cat.codes + 1
df

   item  time
0     1     1
1     2     1
2     3     1
3     4     9
4     5     3
5     6     1

В качестве альтернативы, в зависимости от того, как вы обрабатываете интервалы, вы также можете сделать

bins = np.linspace(df.time.min(), df.time.max() + 1, 10)
pd.cut(df.time, bins=bins, right=False).cat.codes + 1

0    1
1    1
2    1
3    9
4    2
5    1
dtype: int8
25
задан Jim G. 4 October 2009 в 03:10
поделиться

1 ответ

it's not a horrible violation of DDD it's a horrible violation of... well... it's just plain horrible (i say this tongue in cheek) :).

First off, your entity becomes dependent on having a repository... that's not ideal. Ideally you'd want to have your repository create the Person and then assign it everything it needs to be effective in the current domain context.

So when you need a Person, you'll go personRepository.GetPersonWithDefaultEmployer() and get back a person which has default employer populated. The personRepository will have a dependency on an employerRepository and use that to populate the person before returning it.

PersonReposotory : IPersonRepository
{
    private readonly IEmployerRepository employerRepository;

    //use constructor injection to populate the EmployerRepository
    public PersonRepository(IEmployerRepository employerRepository)
    {
        this.employerRepository = employerRepository;
    }

    public person GetPersonWithDefaultEmployer(int personId)
    {
        Person person = GetPerson(personId);
        person.Employer = employerRepository.GetDefaultEmployer(personId);
        return person;
    }
}
23
ответ дан 28 November 2019 в 21:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: