Object-oriented: How should I best structure my application when I want to sort a "primary" model by a property calculated in another "secondary" model?

Question about OO programming, functional programming, NoSQL, SQL databases and software architecture

Hello everyone,

I am an intermediate level self-taught programmer and I have been dying to get an answer to this general question about how to structure my applications. By not having a CS degree and only a few programmer friends, I have not been able to get a solid vision on what is the "right" or "best" way to address this type of problem.

This type of pattern appears everywhere in my current application, and I'm not sure what I should be doing. The pattern is:

I have a database model that is a type of container & # 39; container & # 39; or & # 39; father & # 39 ;, who has many elements that refer to him. For the sake of this, we can use a & # 39; Route & # 39 ;, model that represents a courier driver route for the day.

It has fields like:

- Created time
- Assigned driver
- Notes
- isCompleted
- isReconciled
- serviceCount

I have another database model that is the & # 39; son & # 39; main that refers to the & # 39; father & # 39 ;, in this case, the route. In this case, it is a "service" and represents each one of the stops that the courier service driver must make as part of his route of the day. All services for the relevant route have a reference to the route. The relevant fields in a service are:

- Route <- id referring to the 'parent' model
- Notes
- isCompleted
- isReconciled

In many of these cases, I have a situation in which if you change a service (the child), you may want to update some & # 39; higher level & # 39; or & # 39; summary value & # 39; on the road (the father).

For example:

- When all services are 'complete', update the route to be 'complete'
- When all services are 'reconciled', update the route to be 'reconciled'
- If you add a service to a route, update the 'service count' on the route

Currently, to handle this type of thing, I have functions that normally run after each mutation relevant to a service. It would be called something like updateRouteAfterServiceIsModified. Simply update the route after all modifications to the services, to update these summary values.

However, I understand that if you adopt a more object-oriented approach, you could have some kind of post-save link, or something similar, so if you ever modify a service, the route will be updated. I can see how this could improve code organization, but I can also see how it could be more complicated.

One of the things I have thought about doing is basically never calculating these summary values ​​when making service mutations, since they can be determined on the fly, since they are basically inferred or computable properties. For example:

- To know if the route is complete, just check if all the services are complete
- To know if the route is reconciled, just check if all the services are reconciled
- To know the route count, simply count the number of services, as at the time you need to know

For me, the problem with computing them on the fly is that I will normally have some list of the & # 39; main & # 39; (routes) and I will want to do something like sort by these calculated fields. If the value is not saved in the parent, I have to calculate the value on the fly to sort the list.

I am using Mongo as my data warehouse, and aggregations in foreign fields become quite complicated quite quickly, and other relevant calculations to perform the desired type, and it seems a solution that is too complex and possibly not scalable. But I'm not a mongo expert, so I'm not sure.

I have never used SQL, p. PostgreSQL; I have a friend who has suggested that this kind of thing is much easier in Postgres. It may be possible that what is "normal" to be done in this situation with Postgres is never to keep these summary values ​​in the parent, and simply calculate them at the time of classification, and that Postgres do it efficiently. Perhaps it is the case that the code does not become messy and that it scales well. If that is the case, although the application is primarily built, I would consider switching to Postgres, but I have simply never tried.

In summary, I think there may be 4 possible solutions to this type of problem:

  1. Use a functional programming style and adjust or call functions properly when making mutations & # 39; secondary & # 39; to save all the data you want in the & # 39; main & # 39; model relevant.

  2. Use an object-oriented programming style to maintain these summary / calculated values, saving them in the model & # 39; parent & # 39 ;.

  3. It is not necessary to save these values, calculate them on the fly, Mongo is fine, aggregations can be very powerful, you just have to master them and create some abstractions where it would be useful or simplify your code.

  4. It is not necessary to save these values, and the key to this is to use SQL, which facilitates the classification by a calculated value of strange field, it must change since it makes this type of process trivial.

I'm not sure if there is a "right" approach to this, but it seems such a common pattern in my experience that I would have thought there would be some consensus in the development community about what I should do.

Any help would be greatly appreciated, even if it only directs me to resources that can be useful!

Project structure – Complex roles, permits and management of hierarchical groups in Laravel

I am currently in the planning / feasibility phase of a fairly large web application that must be implemented using Laravel.
My own experience in the subject is quite limited, but I would like to take the opportunity to expand my skills and, if successful, release the code base under the MIT license for anyone to use.

The task in question (sorry for the essay but it is quite complex):

I am working for a company with a fairly complex customer and service structure: we offer multiple services, ranging from risk assessment to education (online and on site) about workplace safety, safety data sheets for products, environmental questions, data protection, etc. . and we want to create a platform that allows us to manage the structure of our clients and services while providing our clients with access to these online services, including API support.
Customers can have completely different business hierarchies, ranging from a small company of 10 employees that only distinguishes between regular and managerial employees to companies with thousands of employees with complex hierarchies that include multiple branches, departments, sites and project management.

Some of our services are site specific, some for departments, some for branches, some for projects (for example, a construction project) and / or for the entire company. We want to have different levels of access for different customer employees and the optional ability for customer administrators to manage their own users / permissions.

The idea was to create a global management platform that would manage the entire structure of clients, users and permits with individual services divided into different applications that are included in the global platform but can be assigned individually to each client with the ability to assign certain roles For users and groups for each application, users can also have multiple group memberships and different roles in different groups.
These applications not only include our services, but also basic functions such as user and group management.
The administration of the platform must be separated from the user's part, which means that our employees must have access through an administrative board and at the same time have the ability to assign a certain client to a certain employee of ours with the permission to administer one or more specific services for this client

Here is the idea of ​​a database structure that had:
Database Structure
Individual services / applications will have their own respective tables, except those that are there for global administration functionality, such as user administration.

The questions I have:

  1. Is this feasible to do with Laravel? If not, what are the alternatives?
  2. Is the structure of my database ok or is it completely stupid for the task at hand?
  3. What are the Laravel supplements that I should analyze?
  4. Any other address, p. folder structure within the laravel project folder, etc.?

rdbms: what database model should I use to organize data sets with an identical structure that cannot be merged?

I have almost no experience with databases, but I have a scenario that I imagine can benefit greatly from some database management system. I have measurements taken during the execution of a machine, essentially a table of several characteristics in every second during the execution. The experiment is performed with different combinations of machine configurations and the tables are placed in a sensitive folder structure to reflect those conditions. The problem is that, although they are readable for humans, the names of the files and folders are not very consistent, so when I want to import the data into Python, or more generally add them in some way, my scripts fail in folders called Speed_4 instead of Speed- 4 and maybe tomorrow someone will name a Speed ​​4 folder. I think that instead of imposing a naming convention, it may be useful to have a system where a new file is recorded with a link to its location on disk together with a set of features of the corresponding machine configuration. Ideally, it would also be possible to create an easy-to-use interface that anyone can use to add new measures.

Also, if at some point I decide that, for example, the location of the experiments is also relevant, it will be difficult to add this to the structure of the folder. This seems like a fairly natural situation in which you want to store multiple data sets along with some relationship between them; perhaps it is difficult for me to write it in a sufficiently broad way that I could not find what the reference approach is. that instance

Perhaps my labels are not very relevant either and I would appreciate suggestions on them to make the publication more precise.

rdbms: what database model should I use to organize data sets with an identical structure that cannot be merged?

I have almost no experience with databases, but I have a scenario that I imagine can benefit greatly from some database management system. I have measurements taken during the execution of a machine, essentially a table of several characteristics in every second during the execution. The experiment is performed with different combinations of machine configurations and the tables are placed in a sensitive folder structure to reflect those conditions. The problem is that, although they are readable for humans, the names of the files and folders are not very consistent, so when I want to import the data into Python, or more generally add them in some way, my scripts fail in folders called Speed_4 instead of Speed- 4 and maybe tomorrow someone will name a Speed ​​4 folder. I think that instead of imposing a naming convention, it may be useful to have a system where a new file is recorded with a link to its location on disk together with a set of features of the corresponding machine configuration. Ideally, it would also be possible to create an easy-to-use interface that anyone can use to add new measures.

Also, if at some point I decide that, for example, the location of the experiments is also relevant, it will be difficult to add this to the structure of the folder. This seems like a fairly natural situation in which you want to store multiple data sets along with some relationship between them; perhaps it is difficult for me to write it in a sufficiently broad way that I could not find what the reference approach is. that instance

Perhaps my labels are not very relevant either and I would appreciate suggestions on them to make the publication more precise.

architecture: AWS environment structure following best practices

I recently completed "AWS Certified Cloud Practitioner 2019" from aCloud.Guru. The course essentially gives you an idea of ​​the different AWS services and some best practices to use along with some practical examples that you can follow along with, e.g. Implement the WordPress site on AWS.

Ultimately, I now have some knowledge left but no "real" experience. My goal is to implement a default installation of nopCommerce 4.20 and have an environment that is useful for a small business.
My idea is to use AWS organizations and have 4 accounts that manage specific tasks; Each account has the minimum privileges to complete its function.
– dev would have written only in global (to pass records)

What I would like to know is what should I consider to exercise if I am missing something. Or is there something you would normally expect to see in this type of configuration, which I missed from my design?

Should security have a separate account? If so, what services should I include?

Finally, I am trying to keep costs as low as possible, so I need to try to monitor costs so that some options do not work. I want to imitate a business environment, but this will come out of my pocket, so my options have some limitations.

enter the description of the image here

front end: DTO structure suitable for a dynamic list of properties

I have an end point /api/properties which returns a dynamic list of properties, p.

{
  userId: 1,
  groupId: 2,
  ...
}

The hard part is that most of the properties are integers (ids) and I would like to show these properties in a human readable format, e.g. instead of the user ID and group ID, I would like to show this:

User: 
Group: 

Then I was thinking of 2 options:

Option 1:

{
  userId: 1,
  groupId: 2,
  ...
  config: {
    userId: {
      label: "User"
      fullName: "fullName"
    },
    groupId: {
      label: "Group"
      name: "name"
    },
    ...
  }
}

Option 2:

(
  {
    name: "userId",
    value: 1,
    label: "User",
    userFullName: "fullName"
  },
  {
    name: "groupId",
    value: 2,
    label: "Group"
    groupName: "name"
  },
  ...
)

Which data structure will be the best for this situation?

c # – Tree structure using composite and visitor pattern

I have the structure Corporation / Company / Installation / Storage and only the Storage could be part of the Installation, and the Installation could be part of the Company, and the Company part of the Corporation. My main problem is that the code works. I need to add the Corporation to itself.

public class BusinessEntityData
{
    public Guid ID { get; set; }

    public Guid ParentID { get; set; }

    public string Title { get; set; }
    public string Number { get; set; }

    public int Type { get; set; }
}

public static class Context
{
    public static List BusinessEntityList { get; set; } = new List();
}

This is what the data entity looks like and the context is for the static list that I am using to test.

public interface IBusinessEntity
{
    string Title { get; set; }
    string Number { get; set; }

    int Type { get; set; }

    List GetChildren(string number);
    void AddBusinessEntity(IBusinessEntity entity);
    void Remove(IBusinessEntity entity);

    void Validate(IParentValidationVisitor visitor, BusinessEntityData data);
}

public interface IValidationVisitor
{
    void VisitCompany(BusinessEntityData data);
    void VisitFacility(BusinessEntityData data);
    void VisitCorporation(BusinessEntityData data);
    void VisitStorage(BusinessEntityData data);

}

These are both interfaces that I use for VisitorPattern and Composite.

Here I implement the interface. Suppose the numbers are unique among all objects.

public abstract class AbstractBusinessEntity : IBusinessEntity
{

    public string Title { get; set; }
    public string Number { get; set; }

    public int Type { get; set; }

    public AbstractBusinessEntity(string number, string title)
    {
        Title = title;
        Number = number;
    }

    public void AddBusinessEntity(IBusinessEntity entity)
    {
        var currentElement = Context.BusinessEntityList.FirstOrDefault(x => x.Number == this.Number);

        var visitor = new ParentValidationVisitor();
        var data = new BusinessEntityData()
        {
            ID = Guid.NewGuid(),
            Title = entity.Title,
            Number = entity.Number,
            Type = entity.Type,
            ParentID = currentElement == null ? Guid.Empty : currentElement.ID
        };

        Validate(visitor, data);
        Context.BusinessEntityList.Add(data);
    }

    public List GetChildren(string number = null)
    {
        if (number == null)
            number = this.Number;

        List list = new List();
        var currentElement = Context.BusinessEntityList.FirstOrDefault(x => x.Number == number);

        if (currentElement == null)
            return new List();

        var children = Context.BusinessEntityList.Where(x => x.ParentID == currentElement.ID);

        foreach(var item in children)
        {
            list.Add(item);
            list.AddRange(GetChildren(item.Number));
        }

        return list;
    }

    public void Remove(IBusinessEntity entity)
    {
        var result = Context.BusinessEntityList.FirstOrDefault(x => x.Number == entity.Number);

        if (result == null)
            return;

        Context.BusinessEntityList.Remove(result);
    }

    public abstract void Validate(IValidationVisitor visitor, BusinessEntityData data);
}

My classes Facility, Corporation, Company Y Storage are inheriting this AbstractBusinessEntity and implement only the Validate method in which I call a separate visitor method.

This is what the visitor looks like:

public class ValidationVisitor : IValidationVisitor
{
    public void VisitCorporation(BusinessEntityData data)
    {
        if (data.Type == (int)Helper.BusinessEntityType.Corporation)
            return;

        if (data.Type == (int)Helper.BusinessEntityType.Company)
            return;

        throw new BusinessEntityValidationException("You can add only Companies to Corporation");

    }
    public void VisitCompany(BusinessEntityData data)
    {
        if (data.Type == (int)Helper.BusinessEntityType.Facility)
            return;

        throw new BusinessEntityValidationException("You can add only Facility to Companies");
    }

    public void VisitFacility(BusinessEntityData data)
    {
        if (data.Type == (int)Helper.BusinessEntityType.Storage)
            return;

        throw new BusinessEntityValidationException("You can add only Storage to Facility");
    }

    public void VisitStorage(BusinessEntityData data)
    {
        throw new BusinessEntityValidationException("You can't add any business entity to Storage");
    }
}

Should the validation be in the pattern of the visitor?

Really strange to me is that when I run the program for this code to work properly, I need to add Corporation to itself, to add the first item in the collection.

        Corporation corporation = new Corporation("Corporation", "Corporation TEst");
        corporation.AddBusinessEntity(corporation);

        var company1 = new Company("Company1", "Company1");
        var company2 = new Company("Company2", "Company2");
        var company3 = new Company("Company3", "Company3");
        corporation.AddBusinessEntity(company1);
        corporation.AddBusinessEntity(company2);
        corporation.AddBusinessEntity(company3);

I am not sure if this is the right way to do it. Another way is that the corporation is outside the tree structure, but I'm not sure if this is correct as a business logic. What could be a better approach?

Here the Github demo for the full code of the example.

Here DotNetFiddle to see a complete example. (not very good readability)

linking: how does the node_modules structure of pnpm avoid circular symbolic links?

I am reading this article explaining the node_modules structure of pnpm. https://pnpm.js.org/en/symlinked-node-modules-structure Set next to the bold text "avoid circular symbolic links" that "package dependencies are placed in the same folder where they are located dependent packages "

I get the following sentence, no matter what dependency of the node_modules folder it is on, since the node will continue to look up one level for a node_modules folder, but I don't understand how circular symbolic links are avoided.

So how does this avoid circular symbolic links?

SEO – Nice site with more than 600 problems with a poor structure. Should I start over?

So I commissioned someone with whom I had a good report to design a WP site for me using a custom theme for my PC services business. I think the style and theme are great, but …

1) He did the job as if I had asked him to create a site for me completely with little or no input in my name. There are many things that I need to change and I find it difficult to do it with unknown add-ons, such as WPBakery Page Builder and Slider Revolution, among others.

2) Without removing anything yet, I performed an audit of the site with SEMrush and there are more than 600 problems and 78 errors:
https://1drv.ms/b/s!AsYZObWoazxfk0phU880wCvNMJfJ?e=d3OPc6

3) He tried to do me a favor by including a lot of premium add-ons, but none is activated and something prevents WP from updating to the latest version. I don't like anything for security.

The website (until ready to go) is https://disabilitybenefitsadvocates-585837.easywp.com/computer-solutions

I wasted a lot of time editing content strictly based on how I had submitted it. As it is now, everything is basically on the home page and is overwhelming. To rank better in the search engines (correct me if I am wrong) I need it structured as:

home page> business description + attractive list of services, all with links> detailed detailed description of the service

I am plagued with indecision. I want this site to keep what it looks like, but it should be easy to use and have a solid structure for the user interface and SEO content. I spent a lot of time researching keywords and variations to determine their ranking probability (most of which is not even visible because I can't decide what to do) and without a completely different structure, everything will be for no.

Above all, at this point I just want the damn thing done because the Google list is fine and receives a lot of traffic, but not having the legitimacy of a site to link it is killing me, so I don't receive calls.

That I have to do?? Should I edit and delete what I want and then correct all these problems that SEMrush reported? I am thinking of crossing it out because I am so tired of not being able to discover how to edit some mosaics and headings and then how do I eliminate much of what I have done without creating more errors?

Any contribution will be greatly appreciated. I think that, after having put all this on paper, the answer is to kindly ask for the theme code and start over on my own, sacrifice some attractive images and keep it free from errors from the beginning. Thanks for your time and consideration.

data structures – Structure alias question

Doing a code analysis. This is how the structure alias is created (and a pointer to the structure):

typedef struct _test
{
    PULONG_PTR var1;
    PULONG_PTR var1;
} test, *ptest;

Then, later in the program, that pointer alias appears again:

Function1(
    _In_ *ptest this_is_my_issue
);

Observe the this_is_my_issue variable.

Finally, in the code, both the pointer alias and the variable I do not understand are used as follows:

ptest this_is_my_issue = NULL;

My question is this:

Is this_is_my_issue just the new name of the ptest value? Maybe I am not providing enough context. I really don't understand how this_is_my_issue The variable comes into play.